"../", 'visit' => array( 'seminar' => array( 'subject' => "KICP _VISIT_ speaker request: _VISITOR_ (Host: _HOST_)", 'message' => "***** _VISIT_ speaker: _VISITOR_ ***** " ), 'term' => array( 'subject' => "Justification required for KICP _VISIT_ visitor request: _VISITOR_ (Host: _HOST_)", 'message' => "Dear _HOST_, You have been listed as host on a _VISIT_ visitor application received from _VISITOR_ [_INSTITUTION_]. As part of the process used to evaluate visitor requests the Visitors & Symposia committee would like you to write a brief email indicating why this visit would be beneficial to KICP. Please also indicate which members of KICP the visitor would most likely interact with and how strongly you support this visit. Please send your response to the visitors and symposia committee at _COMMITTEE_. We will begin our evaluation of the application as soon as we have hear from you. Regards, Visitors & Symposia committee ***** _VISIT_ visitor: _VISITOR_ ***** " ) ), 'form' => array( 'connection' => array( 'main_table' => "visitor", 'write' => 1 ), 'title' => $TITLE{'main'}, 'brief' => "KICP Visitor program", 'submit_button' => "Finish", 'verify_steps' => "", 'introduction' => "Dear prospective visitor,

Please fill out the following brief questioner in order that we can best process your request. For administrative purposes, we have 3 classes of visitors: seminar/colloquium, \"short term\", and \"long term\".

Seminar/Colloquium visits are for those invited to speak at either one of our regular forums or for special seminars. Such visits are usually for a day or two and we typically cover travel expenses (sharing economy class airfare among institutions to the extent possible) and up to two nights lodging.

We encourage longer visits which typically involve collaborative activities with a number of center members. Financial support will be negotiated on a case-by-case basis. Those we call \"short term\" range from 3 days to 2 weeks. \"Long term\" visits are anything over 2 weeks; these require special university approval and thus take a longer time for approval.

All visitors are required to review and agree to follow our KICP Community Values.

Thank you,
KICP Visitors & Symposia Committee ", 'email_visitors' => "vands@kicp.uchicago.edu", 'email_admin' => "seminaradmin@kicp.uchicago.edu", 'email_seminars' => "seminar@kicp.uchicago.edu", 'emails' => array( 'host' => array( 'from' => "_FROM_", 'to' => "_TO_", 'cc' => "_COMMITTEE_, _ADMIN_", 'test' => "egaltseva@kicp.uchicago.edu", 'subject' => "KICP _VISIT_ speaker request: _VISITOR_ (Host: _HOST_)", 'message' => "***** _VISIT_ speaker: _VISITOR_ ***** " ), 'test' => array( 'from' => "", 'to' => "egaltseva@kicp.uchicago.edu", 'subject' => "KICP Visitor", 'message' => "Succesful submission will go to the database" ) ), 'layout' => array( 'text' => "class=\"text\"", 'size' => array( 'year_start' => "2021", 'year_end' => 2023, 'cols' => 40, 'rows' => 5 ) ), 'options' => array( 'host' => array( 'options' => array( "", "Susmita Adhikari", "Adam Anderson", "Daniel Baxter", "Matthew Becker", "Bradford A. Benson", "Nikita Blinov", "Caterine Burroughs", "Victor Buza", "Joao Caldeira", "Marcela Carena", "John E. Carlstrom", "Chihway Chang", "Clarence L. Chang", "Hsiao-Wen Chen", "Anirudh Chiti", "Juan I. Collar", "Thomas M. Crawford", "Cosmin Deaconu", "Alex Drlica-Wagner", "JD Emberson", "Jose Maria Ezquiaga", "Wendy L. Freedman", "Joshua A. Frieman", "Valeri Galtsev", "Elena V Galtseva", "Anne Gambrel", "Martina Gerbino", "Aimee Giles", "Michael D. Gladders", "Nickolay Y. Gnedin", "Luca Grandi", "Jason Henning", "Craig J. Hogan", "Daniel E. Holz", "Daniel Hooper", "Wayne Hu", "Keisuke Inomata", "In Sung Jang", "Alexander Ji", "Austin Joyce", "Kirit S. Karkare", "Richard Kessler", "Edward W. Kolb", "Andrey V. Kravtsov", "Gordan Krnjaic", "Noah Kurinsky", "Patricia Larsen", "Ting Li", "Maureen Lowery", "Amy Lowitz", "Maximus Malacari", "Sam McDermott", "Evan McDonough", "Jeffrey McMahon", "Stephan S. Meyer", "Burcin Mutlu-Pakdil", "Tyler Natoli", "Danielle Norcini", "Eric Oberla", "Angela V. Olinto", "Yuuki Omori", "Antonella Palmese", "Jacques Pienaar", "Paolo Privitera", "Alexandra Sasha Rahlin", "Nesar Soorve Ramachandra", "Marco Raveri", "Malin Nicole Renneby", "Lucas F. Secco", "Anowar J. Shajib", "Erik Shirokoff", "Christine Simpson", "Radomir Smida", "Valerie Smith", "Javier Tiffenberg", "Yu-Dai Tsai", "Abigail G. Vieregg", "Carlos E. M. Wagner", "Scott P. Wakely", "Robert M. Wald", "Lian-Tao Wang", "Ian Wisher", "Michael J Zevin", "Yuanyuan Zhang", "Yiming Zhong" ), 'value_options' => array( "", "389", "317", "360", "365", "204", "368", "380", "382", "369", "264", "21", "363", "98", "194", "399", "19", "165", "315", "304", "327", "384", "323", "17", "1", "91", "362", "374", "106", "195", "109", "277", "351", "206", "254", "229", "10", "388", "397", "394", "395", "396", "85", "108", "9", "329", "366", "352", "337", "379", "342", "336", "372", "392", "398", "7", "393", "370", "385", "319", "6", "391", "383", "345", "196", "320", "376", "335", "375", "386", "390", "294", "364", "359", "353", "290", "367", "284", "111", "97", "112", "231", "339", "387", "328", "381" ) ) ) ), 'host_query' => array( 'tables' => "Member", 'fields' => "concat(First_Name,\" \",MI,\" \", Last_Name) as Person,Email,ID", 'where' => "", 'order' => "Last_Name,First_Name", 'category_field' => "Status", 'start' => "Start_Date", 'finish' => "Finish_Date" ), 'host' => array( array( 'Person' => "Susmita Adhikari", 'Email' => "susmita@stanford.edu", 'ID' => "389" ), array( 'Person' => "Adam Anderson", 'Email' => "adama@fnal.gov", 'ID' => "317" ), array( 'Person' => "Daniel Baxter", 'Email' => "dbaxter@kicp.uchicago.edu", 'ID' => "360" ), array( 'Person' => "Matthew Becker", 'Email' => "mrbecker@anl.gov", 'ID' => "365" ), array( 'Person' => "Bradford A. Benson", 'Email' => "bbenson@astro.uchicago.edu", 'ID' => "204" ), array( 'Person' => "Nikita Blinov", 'Email' => "nblinov@fnal.gov", 'ID' => "368" ), array( 'Person' => "Caterine Burroughs", 'Email' => "cburroughs@uchicago.edu", 'ID' => "380" ), array( 'Person' => "Victor Buza", 'Email' => "vbuza@kicp.uchicago.edu", 'ID' => "382" ), array( 'Person' => "Joao Caldeira", 'Email' => "jcaldeira@uchicago.edu", 'ID' => "369" ), array( 'Person' => "Marcela Carena", 'Email' => "carena@fnal.gov", 'ID' => "264" ), array( 'Person' => "John E. Carlstrom", 'Email' => "jc@kicp.uchicago.edu", 'ID' => "21" ), array( 'Person' => "Chihway Chang", 'Email' => "chihway@kicp.uchicago.edu", 'ID' => "363" ), array( 'Person' => "Clarence L. Chang", 'Email' => "clchang@kicp.uchicago.edu", 'ID' => "98" ), array( 'Person' => "Hsiao-Wen Chen", 'Email' => "hchen@kicp.uchicago.edu", 'ID' => "194" ), array( 'Person' => "Anirudh Chiti", 'Email' => "achiti@mit.edu", 'ID' => "399" ), array( 'Person' => "Juan I. Collar", 'Email' => "collar@kicp.uchicago.edu", 'ID' => "19" ), array( 'Person' => "Thomas M. Crawford", 'Email' => "tcrawfor@kicp.uchicago.edu", 'ID' => "165" ), array( 'Person' => "Cosmin Deaconu", 'Email' => "cozzyd@kicp.uchicago.edu", 'ID' => "315" ), array( 'Person' => "Alex Drlica-Wagner", 'Email' => "kadrlica@fnal.gov", 'ID' => "304" ), array( 'Person' => "JD Emberson", 'Email' => "jemberson@anl.gov", 'ID' => "327" ), array( 'Person' => "Jose Maria Ezquiaga", 'Email' => "ezquiaga@kicp.uchicago.edu", 'ID' => "384" ), array( 'Person' => "Wendy L. Freedman", 'Email' => "wfreedman@uchicago.edu", 'ID' => "323" ), array( 'Person' => "Joshua A. Frieman", 'Email' => "frieman@fnal.gov", 'ID' => "17" ), array( 'Person' => "Valeri Galtsev", 'Email' => "galtsev@kicp.uchicago.edu", 'ID' => "1" ), array( 'Person' => "Elena V Galtseva", 'Email' => "egaltseva@kicp.uchicago.edu", 'ID' => "91" ), array( 'Person' => "Anne Gambrel", 'Email' => "agambrel@kicp.uchicago.edu", 'ID' => "362" ), array( 'Person' => "Martina Gerbino", 'Email' => "mgerbino@anl.gov", 'ID' => "374" ), array( 'Person' => "Aimee Giles", 'Email' => "aimeeg@kicp.uchicago.edu", 'ID' => "106" ), array( 'Person' => "Michael D. Gladders", 'Email' => "gladders@kicp.uchicago.edu", 'ID' => "195" ), array( 'Person' => "Nickolay Y. Gnedin", 'Email' => "gnedin@fnal.gov", 'ID' => "109" ), array( 'Person' => "Luca Grandi", 'Email' => "lgrandi@uchicago.edu", 'ID' => "277" ), array( 'Person' => "Jason Henning", 'Email' => "", 'ID' => "351" ), array( 'Person' => "Craig J. Hogan", 'Email' => "craighogan@uchicago.edu", 'ID' => "206" ), array( 'Person' => "Daniel E. Holz", 'Email' => "dholz@uchicago.edu", 'ID' => "254" ), array( 'Person' => "Daniel Hooper", 'Email' => "dhooper@fnal.gov", 'ID' => "229" ), array( 'Person' => "Wayne Hu", 'Email' => "whu@background.uchicago.edu", 'ID' => "10" ), array( 'Person' => "Keisuke Inomata", 'Email' => "inomata@uchicago.edu", 'ID' => "388" ), array( 'Person' => "In Sung Jang", 'Email' => "isjang@uchicago.edu", 'ID' => "397" ), array( 'Person' => "Alexander Ji", 'Email' => "aji@carnegiescience.edu", 'ID' => "394" ), array( 'Person' => "Austin Joyce", 'Email' => "a.p.joyce@uva.nl", 'ID' => "395" ), array( 'Person' => "Kirit S. Karkare", 'Email' => "kkarkare@kicp.uchicago.edu", 'ID' => "396" ), array( 'Person' => "Richard Kessler", 'Email' => "kessler@kicp.uchicago.edu", 'ID' => "85" ), array( 'Person' => "Edward W. Kolb", 'Email' => "rocky.kolb@uchicago.edu", 'ID' => "108" ), array( 'Person' => "Andrey V. Kravtsov", 'Email' => "andrey@oddjob.uchicago.edu", 'ID' => "9" ), array( 'Person' => "Gordan Krnjaic", 'Email' => "krnjaicg@fnal.gov", 'ID' => "329" ), array( 'Person' => "Noah Kurinsky", 'Email' => "kurinsky@fnal.gov", 'ID' => "366" ), array( 'Person' => "Patricia Larsen", 'Email' => "prlarsen@anl.gov", 'ID' => "352" ), array( 'Person' => "Ting Li", 'Email' => "tingli@fnal.gov", 'ID' => "337" ), array( 'Person' => "Maureen Lowery", 'Email' => "maureenlowery@uchicago.edu", 'ID' => "379" ), array( 'Person' => "Amy Lowitz", 'Email' => "lowitz@uchicago.edu", 'ID' => "342" ), array( 'Person' => "Maximus Malacari", 'Email' => "mmalacari@kicp.uchicago.edu", 'ID' => "336" ), array( 'Person' => "Sam McDermott", 'Email' => "sammcd00@fnal.gov", 'ID' => "372" ), array( 'Person' => "Evan McDonough", 'Email' => "emcdonough@uchicago.edu", 'ID' => "392" ), array( 'Person' => "Jeffrey McMahon", 'Email' => "jeff@astro.uchicago.edu", 'ID' => "398" ), array( 'Person' => "Stephan S. Meyer", 'Email' => "meyer@oddjob.uchicago.edu", 'ID' => "7" ), array( 'Person' => "Burcin Mutlu-Pakdil", 'Email' => "burcinmp@uchicago.edu", 'ID' => "393" ), array( 'Person' => "Tyler Natoli", 'Email' => "tnatoli@uchicago.edu", 'ID' => "370" ), array( 'Person' => "Danielle Norcini", 'Email' => "dnorcini@kicp.uchicago.edu", 'ID' => "385" ), array( 'Person' => "Eric Oberla", 'Email' => "ejo@uchicago.edu", 'ID' => "319" ), array( 'Person' => "Angela V. Olinto", 'Email' => "aolinto@uchicago.edu", 'ID' => "6" ), array( 'Person' => "Yuuki Omori", 'Email' => "yomori@stanford.edu", 'ID' => "391" ), array( 'Person' => "Antonella Palmese", 'Email' => "palmese@fnal.gov", 'ID' => "383" ), array( 'Person' => "Jacques Pienaar", 'Email' => "jpienaar@kicp.uchicago.edu", 'ID' => "345" ), array( 'Person' => "Paolo Privitera", 'Email' => "priviter@kicp.uchicago.edu", 'ID' => "196" ), array( 'Person' => "Alexandra Sasha Rahlin", 'Email' => "arahlin@fnal.gov", 'ID' => "320" ), array( 'Person' => "Nesar Soorve Ramachandra", 'Email' => "nramachandra@anl.gov", 'ID' => "376" ), array( 'Person' => "Marco Raveri", 'Email' => "mraveri@kicp.uchicago.edu", 'ID' => "335" ), array( 'Person' => "Malin Nicole Renneby", 'Email' => "mrenneby@anl.gov", 'ID' => "375" ), array( 'Person' => "Lucas F. Secco", 'Email' => "secco.lf@gmail.com", 'ID' => "386" ), array( 'Person' => "Anowar J. Shajib", 'Email' => "ajshajib@astro.ucla.edu", 'ID' => "390" ), array( 'Person' => "Erik Shirokoff", 'Email' => "shiro@uchicago.edu", 'ID' => "294" ), array( 'Person' => "Christine Simpson", 'Email' => "csimpson@astro.uchicago.edu", 'ID' => "364" ), array( 'Person' => "Radomir Smida", 'Email' => "smida@kicp.uchicago.edu", 'ID' => "359" ), array( 'Person' => "Valerie Smith", 'Email' => "vsmith@oddjob.uchicago.edu", 'ID' => "353" ), array( 'Person' => "Javier Tiffenberg", 'Email' => "javiert@fnal.gov", 'ID' => "290" ), array( 'Person' => "Yu-Dai Tsai", 'Email' => "ytsai@fnal.gov", 'ID' => "367" ), array( 'Person' => "Abigail G. Vieregg", 'Email' => "avieregg@kicp.uchicago.edu", 'ID' => "284" ), array( 'Person' => "Carlos E. M. Wagner", 'Email' => "cwagner@hep.anl.gov", 'ID' => "111" ), array( 'Person' => "Scott P. Wakely", 'Email' => "wakely@ulysses.uchicago.edu", 'ID' => "97" ), array( 'Person' => "Robert M. Wald", 'Email' => "rmwa@midway.uchicago.edu", 'ID' => "112" ), array( 'Person' => "Lian-Tao Wang", 'Email' => "liantaow@uchicago.edu", 'ID' => "231" ), array( 'Person' => "Ian Wisher", 'Email' => "wisher@uchicago.edu", 'ID' => "339" ), array( 'Person' => "Michael J Zevin", 'Email' => "michaelzevin@uchicago.edu", 'ID' => "387" ), array( 'Person' => "Yuanyuan Zhang", 'Email' => "ynzhang@fnal.gov", 'ID' => "328" ), array( 'Person' => "Yiming Zhong", 'Email' => "ymzhong@kicp.uchicago.edu", 'ID' => "381" ) ) ); include_once('../kit/form/form_element.php'); include_once('../kit/form/data/visitor-data.php'); ?> For the Community | Application Visitor Form
Application Visitor Form

1 && isset($FORM{'critical'}) && $FORM{'critical'}) { if (isset($_SESSION{$FORM{'critical'}}) && $_SESSION{$FORM{'critical'}}) { } if (!isset($_SESSION{$FORM{'critical'}}) || !$_SESSION{$FORM{'critical'}}) { # session maybe not OK database has to be checked for succsesful submission if (isset($FORM{'check'}{'field'}) && $FORM{'check'}{'field'} && isset($_POST{'check'}) && $_POST{'check'}) { $resubmit_form = check_submission($FORM{'check'}{'field'},$_POST{'check'},$FORM{'connection'}{'main_table'}); } else { $resubmit_form = 1; } # rescue files: put all files that uploaded on RESUBMIT if (!empty($_FILES)) { $rescue_directory = (isset($UPLOAD_PROPERTY{'rescue_directory'})) ? $UPLOAD_PROPERTY{'rescue_directory'} : $UPLOAD_PROPERTY{'depot_directory'} . '/rescue'; foreach ($_FILES as $file_key => $file_value) { if (!$file_value{'error'}) { $RESCUE_NON = array(); $rescue_from = $file_value{'tmp_name'}; $upload_ok = is_uploaded_file($rescue_from ); $rescue_to = $PAGE{'data'}{'root'} . $rescue_directory . strrchr($rescue_from,'/'); if ($upload_ok) { directory_for_writing($rescue_to); $rescue_ok = copy_file($rescue_from,$rescue_to, $RESCUE_NON); $rescue = $rescue_to; } } } } $_POST = array(); $PARAMS = array(); } } if (empty($_POST) || !isset($PARAMS) || empty($PARAMS)) # empty form { if ($FORM{'session'}) { $_SESSION = array(); $_SESSION{'session_id'} = session_id(); $_SESSION{'start_time'} = time(); } } else { # remove unneeded spaces at the beginning and at the end of the data clean_form_data($PARAMS); # force fields to be empty if (isset($PARAMS,$FORM{'forced_to_empty'})){forced_to_be_empty($PARAMS,$FORM{'forced_to_empty'});} # handel DATE and TIME fields pick_date_fields($PARAMS); # verification fields (wrong or empty) $WRONG = correction_date_time($PARAMS); # E-mail verification $WRONG = array_merge($WRONG,email_verification($PARAMS)); } # PARAMS ----------------------------------------------------------------------- END #!!! #!!! # wrong value in specific fields (check control in the form script or data) if (!isset($FORM{'wrong'}{'message'})) {$FORM{'wrong'}{'message'} = array();} $ITEM_WRONG{'empty_fields'}{'message'} = 'Please fill in the required fields: '; $ITEM_WRONG{'wrong_fields'}{'message'} = 'Wrong value in fields: '; $ITEM_WRONG{'wrong_upload_size'}{'message'} = 'Wrong size of submitted file: '; $ITEM_WRONG{'wrong_upload_format'}{'message'} = 'Wrong format of submitted file: '; $ITEM_WRONG{'wrong_upload_expired'}{'message'} = 'Uploaded file is expired, please upload again: '; # fields which were not in the form but should be in the database $EXTRA_FIELDS = (isset($FORM{'extra_fields'})) ? $FORM{'extra_fields'} : array(); $SIZE = (isset($FORM{'layout'}{'size'})) ? $FORM{'layout'}{'size'} : array(); $MAIL = (isset($FORM{'emails'})) ? $FORM{'emails'} : array(); if (!isset($FORM{'submit_button'}) || !$FORM{'submit_button'}) {$FORM{'submit_button'} = 'Submit'; } $submit_button = $FORM{'submit_button'}; $save_submission = (isset($FORM{'save_submission'})) ? $FORM{'save_submission'} : ''; $action = $_SERVER['REQUEST_URI']; if (isset($PARAMS{'submit'}) && $PARAMS{'submit'}==$save_submission){$save = 1;} $FIELDS = $FORM{'fields'}; if (!isset($FORM{'connection'}{'main_table'})){$FORM{'connection'}{'main_table'} = '' ;} # set 'main_table' (if there is NO table_name) $FIELDS_ALL = add_table_and_record($FIELDS{'fields'}); # array of all form fields to proceed # Submitter name $DATA_IN_SESSION = ($FORM{'session'} && isset($_SESSION)) ? $_SESSION : array(); if (isset($PAGE{'data'}{'auth_user_name'}) && $PAGE{'data'}{'auth_user_name'}) { $FORM{'submitter_name'} = $PAGE{'data'}{'auth_user_name'}; } else { $FORM{'submitter_name'} = (isset($FORM{'submitter_name'}) && $FORM{'submitter_name'}) ? submitter_name($FIELDS{'fields'},$PARAMS,$DATA_IN_SESSION) : 'Colleague'; } $FORM{'submitter_name'} = clean_untrusted_string($FORM{'submitter_name'}); if (isset($FORM{'introduction'})) { $FORM{'introduction'} = str_replace('_SUBMITTER_',$FORM{'submitter_name'},$FORM{'introduction'}); } if (!isset($FORM{'messages'})){$FORM{'messages'} = array();} # data has been sent if (!isset($FORM{'messages'}{'info_sent'})) { $FORM{'messages'}{'info_sent'} = 'The submitted information is listed below.'; } # data don't sent if (!isset($FORM{'messages'}{'info_not_sent'})) { $FORM{'messages'}{'info_not_sent'} = 'Your information has NOT been sent.'; } # review data if (!isset($FORM{'messages'}{'review'})) { $FORM{'messages'}{'review'} = 'Please review the information listed below. If the information is correct, please press "SUBMIT" to NEXT. Otherwise, please press "Return to the Form" to make corrections.'; } # review attachments if (!isset($FORM{'messages'}{'review_attached'})) { $FORM{'messages'}{'review_attached'} = 'Please review the attached document. To submit this document and NEXT, please press "SUBMIT". Otherwise, please press "Return to the Form" to make corrections.'; } if (!isset($FORM{'messages'}{'resubmit_form'})) { $FORM{'messages'}{'resubmit_form'} = 'Your session has expired. Please re-submit the form.'; } # saved submission if (!isset($FORM{'messages'}{'saved'})) { if (!isset($FORM{'identity'})){$FORM{'identity'} = '';} $FORM{'messages'}{'saved'} = 'The draft submission has been saved, but the submission has not been submitted.'; } if (isset($FORM{'saved_link'}) && $FORM{'saved_link'}) { $FORM{'messages'}{'saved'} .= ' To review the draft please visit: ' . $FORM{'saved_link'} . '.'; } if (!empty($FORM{'messages'})) { foreach ($FORM{'messages'} as $key => $value) { if (strstr($value,'_PERSON_')) { $FORM{'messages'}{$key} = str_replace('_PERSON_',$FORM{'submitter_name'},$value); } if (strstr($value,'_SUBMITTER_')) { $FORM{'messages'}{$key} = str_replace('_SUBMITTER_',$FORM{'submitter_name'},$value); } elseif (strstr($value,'SUBMITTER')) { $FORM{'messages'}{$key} = str_replace('SUBMITTER',$FORM{'submitter_name'},$value); } $FORM{'messages'}{$key} = text_vs_html($FORM{'messages'}{$key},'html'); } } # prompt on screen for submission steps if (!isset($FORM{'step_continue'})){$FORM{'step_continue'} = 'advance to the next step';} if (!isset($FORM{'step_finish'})){$FORM{'step_finish'} = 'complete the submission process';} # handel upload files # if update website is separated from the real website if (!isset($PAGE{'data'}{'extra_path_for_upload'})){$PAGE{'data'}{'extra_path_for_upload'} = '';} $PAGE{'data'}{'root_upload'} = $PAGE{'data'}{'root'} . $PAGE{'data'}{'extra_path_for_upload'}; $UPLOAD_ERROR = handel_uploaded_files($PARAMS, $FIELDS_ALL,$upload_directory,$PAGE{'data'}{'root_upload'}); $UPLOAD_NAMES = ($FORM{'session'} && isset($_SESSION{'uploaded_names'})) ? $_SESSION{'uploaded_names'} : array() ; add_user_file_name($FIELDS_ALL,$UPLOAD_NAMES); # proceeding steps $number_steps = steps_number($FIELDS_ALL); $current_step = (isset($PARAMS{'step'}) && $PARAMS{'step'}) ? $PARAMS{'step'} : 1; $security_field = ''; # add security image with '$PAGE{'data'}{'security_image'}' name field for the first form step $security_field = ''; $security_status = ''; $FORM{'resubmit'} = 0; # form has to be resubmited IF the session is lost during multiple form (with number of steps>1) $FIELDS_FOR_STEP = processing_steps($FIELDS_ALL,$current_step,$number_steps,$security_field,$submit_button,$security_status); # add alert property (field either WRONG or EMPTY) $FIELDS_FOR_STEP = alert_field_property($FIELDS_FOR_STEP,$WRONG); $STEPS = $FIELDS; $STEPS{'fields'} = $FIELDS_FOR_STEP; $string = ''; $ARRAY = array(); $message_box = ''; $message = ''; $form = ''; $info = ''; $hr = 0; $transfer_id = 0; $FORM{'name'} = (isset($FORM{'name'})) ? $FORM{'name'} : 'form' ; $FORM{'layout'}{'text'} = (isset($FORM{'layout'}{'text'})) ? $FORM{'layout'}{'text'} : '' ; # $_POST{'Transfer'} - if data were tranferd from another form $POSITION_HERE[] = 'START form'; if ((empty($_POST) && (!isset($PARAMS) || empty($PARAMS))) || (isset($_POST{'Transfer'}) && $_POST{'Transfer'})) # empty form { $POSITION_HERE[] = 'EMPTY form'; if ($resubmit_form && isset($FORM{'messages'}{'resubmit_form'})) { $message = $FORM{'messages'}{'resubmit_form'}; } else { $message = (isset($FORM{'introduction'})) ? $FORM{'introduction'} : ''; } $FORM{'messages'}{'empty_form'} = (isset($FORM{'messages'}{'empty_form'})) ? $FORM{'messages'}{'empty_form'} : '' ; $message .= (isset($FORM{'search'}) && $FORM{'search'}) ? '' : $FORM{'messages'}{'empty_form'}; $form = all_form($STEPS,$action,$SIZE,$submit_button,$hr,$security_field,$FORM{'name'},'',$save_submission); } else # validation info from the form { { $POSITION_HERE[] = 'VALIDATION form'; $something_wrong = 0; $success = 0; # to put data into 'Attempt' table # empty requested upload file if (isset($UPLOAD_ERROR{'empty'}) && is_array($UPLOAD_ERROR{'empty'}) && !empty($UPLOAD_ERROR{'empty'})){$EMPTY = array_merge($EMPTY,$UPLOAD_ERROR{'empty'});} # empty requered field $EMPTY = array_merge($EMPTY,empty_form_fields($FIELDS_FOR_STEP)); $ITEM_WRONG{'empty_fields'}{'fields'} = select_property($EMPTY,'title'); $UPLOAD_ERROR{'size'} = (isset($UPLOAD_ERROR{'size'})) ? $UPLOAD_ERROR{'size'} : array(); $UPLOAD_ERROR{'format'} = (isset($UPLOAD_ERROR{'format'})) ? $UPLOAD_ERROR{'format'} : array(); $ITEM_WRONG{'wrong_upload_size'}{'fields'} = select_property($UPLOAD_ERROR{'size'},'error'); $ITEM_WRONG{'wrong_upload_format'}{'fields'} = select_property($UPLOAD_ERROR{'format'},'error'); # wrong fields (DATE) # wrong security code if ($security_status=='wrong' && !in_array($security_field,select_property($EMPTY,'name'))){$WRONG[] = $security_field;} $ITEM_WRONG{'wrong_fields'}{'fields'} = field_title_by_name($FIELDS_FOR_STEP,$WRONG); # remove empty fields from wrong fields (if any) if (is_array($ITEM_WRONG{'empty_fields'}{'fields'}) && !empty($ITEM_WRONG{'empty_fields'}{'fields'}) && is_array($ITEM_WRONG{'wrong_fields'}{'fields'}) && !empty($ITEM_WRONG{'wrong_fields'}{'fields'})) { $ITEM_WRONG{'wrong_fields'}{'fields'} = array_values(array_diff($ITEM_WRONG{'wrong_fields'}{'fields'},$ITEM_WRONG{'empty_fields'}{'fields'})); } $message = status_for_wrong_fields($ITEM_WRONG,$something_wrong,$FORM{'wrong'}{'message'}); if ($FORM{'session'}){set_values($FIELDS_ALL,$_SESSION);} set_values($FIELDS_ALL,$PARAMS); # re-upload file $TO_REUPLOAD = array(); if (isset($UPLOAD_ERROR{'to_reupload'}) && is_array($UPLOAD_ERROR{'to_reupload'}) && !empty($UPLOAD_ERROR{'to_reupload'})) { $TO_REUPLOAD = $UPLOAD_ERROR{'to_reupload'}; } if (!isset($PARAMS{'submit'}) || (isset($PARAMS{'submit'}) && ($something_wrong || stristr($PARAMS{'submit'},'return') || stristr($PARAMS{'submit'},'add') || !empty($TO_REUPLOAD)) && $PARAMS{'submit'}!=$save_submission)) # if something WRONG and it's not 'save submission' { if ($something_wrong) # if some of required fields are not filled OR wrong data { $POSITION_HERE[] = 'WRONG data'; } elseif (!empty($TO_REUPLOAD)) { $POSITION_HERE[] = 'REUPLOAD files'; } else { $POSITION_HERE[] = 'data OK: ' . $PARAMS{'submit'}; } $form = all_form($STEPS,$action,$SIZE,$submit_button,$hr,$security_field,$FORM{'name'},'',$save_submission); } elseif ($save) # save submission { $POSITION_HERE[] = 'SAVE submission'; $action_save = $_SERVER{'SCRIPT_NAME'}; # path without params $FIELDS_FOR_STEP = processing_steps($FIELDS_ALL,$current_step,$number_steps,$security_field,$submit_button,$security_status); $STEPS = $FIELDS; $STEPS{'fields'} = $FIELDS_FOR_STEP; $message = $FORM{'messages'}{'saved'}; $FIELDS_SAVE = $STEPS{'fields'}; # hidden form will be created later after data are put into the database and main ID is return $info = all_info($STEPS{'fields'},$PAGE{'data'}{'root_upload'}); } else # everything is OK { $POSITION_HERE[] = 'SUBMISSION ok'; # drop all security fields relavent to security $STEPS{'fields'} = drop_security_fields($STEPS{'fields'}); $info = all_info($STEPS{'fields'},$PAGE{'data'}{'root_upload'}); # submitter will verify the information (if needed) $verified_ok = 'OK'; if (isset($PARAMS{'verify'}) && $PARAMS{'submit'}!=$verified_ok && $PARAMS{'submit'}!=$FORM{'submit_button'}) { $POSITION_HERE[] = 'VERIFY submission'; # for review message for attached document $ATTECHED_FOR_STEP = find_by_property($STEPS{'fields'},'type','File'); $message = (is_array($ATTECHED_FOR_STEP) && !empty($ATTECHED_FOR_STEP) && $FORM{'messages'}{'review_attached'}) ? $FORM{'messages'}{'review_attached'} : $FORM{'messages'}{'review'}; # different messages for continue and finish steps if (strstr($message,'NEXT')) { $next_replace = ($current_step==$number_steps) ? $FORM{'step_finish'} : $FORM{'step_continue'}; if (!$next_replace){$next_replace = 'continue';} $message = str_replace('NEXT',$next_replace,$message); } $verify_button = ($current_step<$number_steps) ? $verified_ok : $FORM{'submit_button'}; $message = str_replace('SUBMIT',$verify_button,$message); $form = hidden_form($STEPS{'fields'},$action,$verify_button); } else { $POSITION_HERE[] = 'put values into session'; # put verified data into $_SESSION put_values_into_session($STEPS{'fields'}); $current_step++; $PARAMS{'step'} = $current_step; # go to the next step if ($current_step<=$number_steps) { $POSITION_HERE[] = 'go to the next step'; $FIELDS_FOR_STEP = processing_steps($FIELDS_ALL,$current_step,$number_steps,$security_field,$submit_button,$security_status); $STEPS = $FIELDS; $STEPS{'fields'} = $FIELDS_FOR_STEP; $form = all_form($STEPS,$action,$SIZE,$submit_button,$hr,$security_field,$FORM{'name'},'',$save_submission); $info = ''; $message = ''; } else # submission is about to finish (if we did not loose uploaded filed due to very long submission) { $POSITION_HERE[] = 'submission is about to finish'; # set field values from $_SESSION if ($FORM{'session'}){set_values($FIELDS_ALL,$_SESSION);} # expired uploaded files (for very long submission) $EXPIRED = check_expired_upload_files($FIELDS_ALL,$PAGE{'data'}{'root_upload'}); if (!empty($EXPIRED)) { $POSITION_HERE[] = 'there are EXPIRED files'; $PARAMS{$EXPIRED{'value'}} = ''; $FIELDS_FOR_STEP = processing_steps($FIELDS_ALL,$current_step,$number_steps,$security_field,$submit_button,$security_status,$EXPIRED{'name'}); $STEPS = $FIELDS; $STEPS{'fields'} = $FIELDS_FOR_STEP; $form = all_form($STEPS,$action,$SIZE,$submit_button,1,$security_field); $info = ''; $message = $ITEM_WRONG{'wrong_upload_expired'}{'message'} . ' ' . $EXPIRED{'title'}; } else { $POSITION_HERE[] = 'SUCCESS'; $success = 1; if ($verify_at_end && $PARAMS{'submit'}!=$FORM{'submit_button'}) # verify all information before final submit { $POSITION_HERE[] = 'verify all information before final submit'; $success = 0; $message = str_replace('NEXT',$FORM{'step_finish'},$FORM{'messages'}{'review'}); $verify_button = $FORM{'submit_button'}; $FIELDS_FOR_STEP = processing_steps($FIELDS_ALL,$current_step,$number_steps,$security_field,$submit_button,$security_status); $STEPS = $FIELDS; $STEPS{'fields'} = $FIELDS_FOR_STEP; $info = all_info($STEPS{'fields'},$PAGE{'data'}{'root_upload'}); $form = hidden_form($STEPS{'fields'},$action,$verify_button,$save_submission); } } } } } if (isset($FORM{'not_for_database'}) && $FORM{'not_for_database'}) # data from form are NOT going into the database { $POSITION_HERE[] = 'data NOT into the database'; if ($success) { $ARRAY{'data'} = (isset($_SESSION) && !empty($_SESSION)) ? $_SESSION : $PARAMS; } } else # data from form are going into the database { # put data into database: succes and all attempts (if data should go into the database) if ($success || $save || (isset($CONNECTION{'write_attempt'}) && $CONNECTION{'write_attempt'})) { # put data into the database (main and Attempt tables) # all fields with not empty data from form if ($success || $save) # put uploaded files into state directoty (DEPOT) and update $DATA_FIELDS with new NAMES for uploaded files { if (!isset($UPLOAD_PROPERTY{'version_separator_for_upload'})) { $UPLOAD_PROPERTY{'version_separator_for_upload'} = '' ;} if (!isset($UPLOAD_PROPERTY{'tables_for_naming'})){$UPLOAD_PROPERTY{'tables_for_naming'} = array(); } working_with_uploaded_files($FIELDS_ALL,$UPLOAD_PROPERTY{'depot_directory'},$UPLOAD_PROPERTY{'version_separator_for_upload'},$UPLOAD_PROPERTY{'tables_for_naming'},$PAGE{'data'}{'root_upload'}); } # put data into the database if ((isset($CONNECTION{'write'}) && $CONNECTION{'write'} && $success) || (isset($CONNECTION{'write'}) && $CONNECTION{'write'} && $save)|| (isset($CONNECTION{'write_attempt'}) && $CONNECTION{'write_attempt'})) { if ($save_submission) # add extra field for main table { $submission_status = $PARAMS{'submit'}; if ($success){$submission_status = 'submitted';} elseif ($save){$submission_status = 'saved';} $FORM{'extra_fields'}{$FORM{'connection'}{'main_table'}}{'Submission_Status'} = $submission_status; } $success_save = ($success || $save) ? 1 : 0; if (!$success_save) { $here_position = 'write attempt'; # put Submit button value and Message on the screen in mainAttempt table $verify_ok = ($something_wrong) ? 'Wrong' : 'Verify'; $HERE{'attempt_status_field'} = 'Attempt'; $FORM{'extra_fields'}{$FORM{'connection'}{'main_table'}}{$HERE{'attempt_status_field'}} = $verify_ok . ' | '; $FORM{'extra_fields'}{$FORM{'connection'}{'main_table'}}{$HERE{'attempt_status_field'}} .= (isset($PARAMS{'submit'})) ? $PARAMS{'submit'} : 'Submit button is not defined'; $FORM{'extra_fields'}{$FORM{'connection'}{'main_table'}}{$HERE{'attempt_status_field'}} .= ' | ' . strip_tags($message); } else { $here_position = ($save) ? 'save' : 'success'; } $POSITION_HERE[] = 'data -> database (' . $here_position . ')'; if (isset($PARAMS{'submit'})) { $main_record_ID = populate_database($CONNECTION,$FIELDS_ALL,$FORM,$success_save,$PARAMS{'submit'}); $FORM{'updated_main_ID'} = $main_record_ID; if ($save && $FORM{'updated_main_ID'}) # create hidden form for saved record with return main ID { if ($message){$message .= '

';} $message .= 'To continue submission click ' . site_www('here',$action_save . '?ID=' . $FORM{'updated_main_ID'}) . '.'; $form = ''; # form ends after the save } } if (isset($FORM{'external'}{'transfer_id'}) && $success) { $POSITION_HERE[] = 'external: transfer_id'; $transfer_id = $main_record_ID; } } } } } } if ($success) # result INFO on screen or send data to other form { # send data to EXTERNAL server to process $POSITION_HERE[] = 'send data to EXTERNAL server to process'; if (isset($FORM{'external'}{'fields'}) && is_array($FORM{'external'}{'fields'}) && !empty($FORM{'external'}{'fields'})) { if ($FORM{'external'}{'site_url'}){$action = $FORM{'external'}{'site_url'};} if (isset($FORM{'external'}{'introduction'}) && $FORM{'external'}{'introduction'}) { $FORM{'external'}{'introduction'} = str_replace(array('_PERSON_','_SUBMITTER_','SUBMITTER'),$FORM{'submitter_name'},$FORM{'external'}{'introduction'}); } # transfer ID of main record if (isset($FORM{'external'}{'transfer_id'}{'name'}) && $FORM{'external'}{'transfer_id'}{'name'} && $transfer_id) { $FORM{'external'}{'transfer_id'}{'name'} = add_table_and_record_to_field($FORM{'external'}{'transfer_id'}); $FORM{'external'}{'transfer_id'}{'value'} = $transfer_id; if (isset($FORM{'external'}{'transfer_id'}{'table'})){unset($FORM{'external'}{'transfer_id'}{'table'});} if (isset($FORM{'external'}{'transfer_id'}{'record'})){unset($FORM{'external'}{'transfer_id'}{'record'});} if (!isset($FORM{'external'}{'fields'})){$FORM{'external'}{'fields'} = array();} $FORM{'external'}{'fields'}[] = $FORM{'external'}{'transfer_id'}; } $STEPS{'fields'} = external_fields($FORM{'external'}{'fields'}); $form = all_form($STEPS,$action,$SIZE,$FORM{'external'}{'submit_button'},0,'',$FORM{'external'}{'form_name'},'top'); $message = (isset($FORM{'external'}{'introduction'})) ? $FORM{'external'}{'introduction'} : ''; $info = ''; } else # ends submission HERE on this server { $POSITION_HERE[] = 'ends submission HERE on this server'; # display submission result on applicant screen $info = all_info($FIELDS_ALL,$PAGE{'data'}{'root_upload'}); $message = (isset($FORM{'messages'}{'info_sent'})) ? $FORM{'messages'}{'info_sent'} : '' ; $form = ''; } # add info related to main_record_ID if ($message && $main_record_ID) { $infor_main_record_ID = (isset($FORM{'function_for_id'}) && $FORM{'function_for_id'}) ? $FORM{'function_for_id'}($main_record_ID) : $main_record_ID ; $message = str_replace('_FORM:ID_',$infor_main_record_ID,$message); } } # !!!! # send e-mails $MAIL = (isset($FORM{'emails'})) ? $FORM{'emails'} : array(); if ((!empty($_POST) || !empty($PROMPT)) && is_array($MAIL) && !empty($MAIL)) { $message_with_form_fields = ($_POST) ? form_email($FIELDS_ALL) : ''; foreach ($MAIL as $key => $VALUE) { if ($key!='test') # to committee or administrator for approval { if (isset($success) && $success) # successfull submission to orgcommittee or administrator for approval { # email to submitter $E_SUBMITTER = find_by_property($FIELDS_ALL,'name',$VALUE{'to'}); if (isset($E_SUBMITTER{'value'}) && $E_SUBMITTER{'value'}) { $POSITION_HERE[] = 'SEND e-mail (not test): ' . $VALUE{'to'}; $VALUE{'to'} = $E_SUBMITTER{'value'}; } if (isset($VALUE{'message'}) && strstr($VALUE{'message'},'SUBMITTER')){$VALUE{'message'} = str_replace('SUBMITTER',$FORM{'submitter_name'},$VALUE{'message'});} if ((!isset($FORM{'approval'}) || !$FORM{'approval'}) && (!isset($VALUE{'no_data_in_message'}) || !$VALUE{'no_data_in_message'})) # put all submitted data into email { $VALUE{'message'} .= $message_with_form_fields; } $send_mail = send_email($VALUE); } } else # for backup purpose for tester { $POSITION_HERE[] = 'SEND e-mail (test)'; if ((isset($CONNECTION{'email_test_ok'}) && $CONNECTION{'email_test_ok'}) || !isset($PARAMS{'submit'}) || strtolower($PARAMS{'submit'})!='ok') { if (!isset($VALUE{'subject'})){$VALUE{'subject'} = '' ;} $VALUE{'subject'} .= ' [' . getenv('REMOTE_ADDR') . '] '; # normal step if ($message_with_form_fields){$VALUE{'subject'} .= (isset($PARAMS{'submit'})) ? $PARAMS{'submit'} : 'Submit button is not defined';} # session closed elseif (!empty($PROMPT)) { $PROMPT{'step_finish'} = time(); $step_duration = $PROMPT{'step_finish'} - $PROMPT{'step_start'}; $step_duration_hour = $step_duration/3600; $step_duration_hour = (int) $step_duration_hour; $step_duration_hour = ($step_duration_hour) ? $step_duration_hour . ' hour; ' : '' ; $step_duration_min = ($step_duration - $step_duration_hour*3600)/60; $step_duration_min = (int) $step_duration_min; $step_duration_min = ($step_duration_min) ? $step_duration_min . ' min; ' : '' ; $step_duration_sec = $step_duration - $step_duration_hour*3600 - $step_duration_min*60 . ' sec'; $step_duration = $step_duration_hour . $step_duration_min . $step_duration_sec; $VALUE{'subject'} .= ($resubmit_form) ? ' Session crash' : ' Reload or Back'; $VALUE{'subject'} .= ' (idle: ' . $step_duration . ')'; if (isset($rescue) && $rescue){$PROMPT{'rescue'} = $rescue;} $PROMPT{'step_start'} = date('H:i:s j F, Y',$PROMPT{'step_start'}); $PROMPT{'step_finish'} = date('H:i:s j F, Y',$PROMPT{'step_finish'}); $prompt_number = 1; foreach ($PROMPT as $prompt_key =>$prompt_value) { $message_with_form_fields .= $prompt_number . ') '. $prompt_key . ': ' . $prompt_value . "\n"; $prompt_number ++; } if (!empty($_FILES)) { $files_number = 1; $message_with_form_fields .= "\n" . 'FILES' . "\n"; foreach ($_FILES as $files_key => $files_value) { $message_with_form_fields .= $files_number . ') '. $files_key . ': ' . implode(array($files_value{'tmp_name'},$files_value{'type'},$files_value{'size'}),' | ') . "\n"; $files_number ++; } } } if (!isset($VALUE{'message'} )) {$VALUE{'message'} = '';} # changes for updated record $string_changes = ''; if (isset($FORM{'changes'}) && strtolower($FORM{'changes'}{'type'})=='update') { $string_changes = string_for_database_changes($FORM{'changes'}{'fields'}); } if (!isset($FORM{'changes'}{'type'})){$FORM{'changes'}{'type'} = 'unsuccessfull attempt' ;} $VALUE{'message'} .= "\n" . strtoupper($FORM{'changes'}{'type'}); # add SCRIPT FILENAME if (isset($_SERVER{'SCRIPT_FILENAME'}) && $_SERVER{'SCRIPT_FILENAME'}) { $VALUE{'message'} .= "\n" . $_SERVER{'SERVER_NAME'} . ':' . $_SERVER{'SCRIPT_FILENAME'} ; # add QUERY_STRING if (isset($_SERVER{'QUERY_STRING'}) && $_SERVER{'QUERY_STRING'}) { $VALUE{'message'} .= '?' . $_SERVER{'QUERY_STRING'} ; } } $VALUE{'message'} .= "\n*****\n"; $VALUE{'message'} .= ($string_changes) ? $string_changes : $message_with_form_fields ; $will_be = ($message) ? strip_tags($message) : 'NO prompt message on the screen' ; $VALUE{'message'} .= "\n**********\n" . 'The Message to the submitter after submiting the form will be:' . "\n" . $will_be ; $VALUE{'message'} .= "\n\n------ POST ---------"; if (!empty($_POST)) { foreach ($_POST as $key_here => $value_here) { $VALUE{'message'} .= "\n" . $key_here . ': '; $VALUE{'message'} .= (is_array($value_here)) ? implode($value_here,'|') : $value_here; } } $VALUE{'message'} .= "\n\n------ PARAMS ---------"; if (!empty($PARAMS)) { foreach ($PARAMS as $key_here => $value_here) { $VALUE{'message'} .= "\n" . $key_here . ': '; $VALUE{'message'} .= (is_array($value_here)) ? implode($value_here,'|') : $value_here; } } # POSITION_HERE $VALUE{'message'} .= "\n\n------ POSITION HERE ---------\n"; if (!empty($POSITION_HERE)) { $VALUE{'message'} .= implode($POSITION_HERE,' | '); } $send_mail = send_email($VALUE); } } } } # !!! # clean the SESSION values (if submission is success) if (isset($success) && $success) { if(isset($_SESSION) && !empty($_SESSION)){$_SESSION = array();} } # OUTPUT if ($message){$message = alert_box($message);} $string = $message; $string .= $info; $string .= $form; if (!$return_main_ID) { if (isset($FORM{'not_for_database'}) && $FORM{'not_for_database'} && (!isset($FORM{'return_string'}) || !$FORM{'return_string'})) { $ARRAY{'string'} = $string; $ARRAY{'ok'} = ($success) ? 1 : 0; return $ARRAY; } else { return $string; } } else { $ARRAY{'string'} = $string; $ARRAY{'id'} = (isset($main_record_ID)) ? $main_record_ID : 0; return $ARRAY; } } #::::::::::::::::::::::::::::::::::: function select_query($QUERY,$path_to_root='',$type='html',$CONNECT_OWN=array()) { $print_name = 'select_query'; global $CONNECTION,$PAGE; $array = array(); $CONNECT_DB = (is_array($CONNECT_OWN) && !empty($CONNECT_OWN)) ? $CONNECT_OWN : $CONNECTION ; if ((!isset($QUERY{'tables'}) || !$QUERY{'tables'}) && isset($QUERY{'table'}) && $QUERY{'table'}) { $QUERY{'tables'} = $QUERY{'table'}; } if (!isset($QUERY{'tables'})){$QUERY = array();} if (is_array($QUERY) && !empty($QUERY)) { $connect = database_connection($CONNECT_DB); if (!$connect){ echo mysqli_connect_errno() ;} else { # function returns assos array $array{table_field} - records from database if (isset($QUERY{'fields'}) && !empty($QUERY{'fields'})) { if (is_array($QUERY{'fields'})) { $QUERY{'fields'} = implode($QUERY{'fields'},','); } } else {$QUERY{'fields'} = '*';} $QUERY_RESULT = array(); $QUERY{'where'} = (isset($QUERY{'where'}) && $QUERY{'where'}) ? ' where ( ' . $QUERY{'where'} . ')' : '' ; $QUERY{'order'} = (isset($QUERY{'order'}) && $QUERY{'order'}) ? ' order by ' . $QUERY{'order'} : '' ; $QUERY{'limit'} = (isset($QUERY{'limit'}) && $QUERY{'limit'}) ? ' limit ' . $QUERY{'limit'} : '' ; $Query_string = ' select ' . $QUERY{'fields'} . ' from ' . $QUERY{'tables'} . ' ' . $QUERY{'where'} . ' ' . $QUERY{'order'} . ' ' . $QUERY{'limit'}; $Select = mysqli_query($connect,$Query_string); if (mysqli_errno($connect)) { printf("Errorcode: %d\n", mysqli_errno($connect)); print '
Query: (' . $print_name . ')' . $Query_string . '
'; } else { $number_rows = mysqli_num_rows($Select); $number_fields = mysqli_num_fields($Select); $Table_fields = array(); for ($i=0; $i<$number_fields; $i++) { $finfo = mysqli_fetch_field_direct($Select,$i); $Table_fields[$i] = $finfo->name; } if ($number_rows > 0) { $k = -1; while($row = mysqli_fetch_assoc($Select)) { $k++; for ($i=0; $i<$number_fields; $i++) { $array[$k][$Table_fields[$i]] = $row[$Table_fields[$i]]; } } } } $Free_memory = mysqli_free_result($Select); if (!$Free_memory){mysqli_errno($connect);} } } if (isset($connect) && $connect){mysqli_close($connect);} return $array; } #::::::::::::::::::::::::::::::::::: function month_array() { $number = 12; $year = date('Y'); $ARRAY = array(); for ($i=1; $i<=$number; $i++) { $month_time = mktime(0,0,0,$i,1,$year); $ARRAY{'value'}[$i] = ($i<10) ? "0".$i."" : $i ; $ARRAY{'name'}[$i] = date('F',$month_time); } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function notnull_by_other_field(&$FIELDS,$PARAMS,$TARGET,$CONDITION,$condition_string) { # function changes 'not_null' property (1->0) of 'target' fields by comparising value of 'condition' field and $condition_string if (is_array($TARGET) && !empty($TARGET) && is_array($CONDITION) && !empty($CONDITION)) { # find 'full' name for condition field $condition_field_name = full_name_for_form_field($CONDITION,$FIELDS); if ($condition_field_name && $PARAMS{$condition_field_name} && $PARAMS{$condition_field_name}!=$condition_string) { # change not value 1 -> 0 for target field change_attribute_of_specifid_field($FIELDS,$TARGET,'not_null',$new_attribute_value=0); } } } #::::::::::::::::::::::::::::::::::: function reference_form_fields($ARRAY,$number_records,$start_record=1,$notnull=0,$step=1,$table='reference',$text='',$class='') { global $PARAMS; # FORCED = array(array('main'=array(field that defines other fields to be empty),'forced'=>array(array of fields thatforced to be empty by 'main'))) # NOT NULL propety $notnull_record = 0 ; $GROUP = array(); if (!empty($notnull)) { if (is_array($notnull)) { $VALUES = $notnull{'values'}; # fields for which not_null can be 0 or 1 $KEYS = $notnull{'keys'}; # fields that defines not_null value for VALUES $number = count($KEYS); if (!empty($VALUES)) { for ($i=0; $i<$number; $i++) { $ITEMS = array('name'=>$KEYS[$i],'table'=>$table); $GROUP[] = $ITEMS; } } } else {$notnull_record = 1 ;} } $FIELDS = array(); $number_items = count($ARRAY); for ($i=0; $i<$number_records; $i++) { $record = $start_record + $i; # add record number to GROUP array (if there is an array) if (!empty($GROUP)) { $number_in_group = count($GROUP); for ($j=0; $j<$number_in_group; $j++) { $GROUP[$j]{'record'} = $record; } } if ($text) { $TITLE = array(); $TITLE{'text'} = $text .' # ' . $record ; $TITLE{'step'} = $step; $TITLE{'record'} = $record; if ($class){$TITLE{'class'} = $class;} $FIELDS[] = $TITLE; } for ($j=0; $j<$number_items; $j++) { $ITEM = array(); $ITEM{'name'} = $ARRAY[$j]{'name'}; $ITEM{'table'} = $table; $ITEM{'step'} = $step; $ITEM{'record'} = $record; $ITEM{'title'} = $ARRAY[$j]{'title'}; $ITEM{'type'} = (isset($ARRAY[$j]{'type'}) && $ARRAY[$j]{'type'})? $ARRAY[$j]{'type'} : 'text'; if (isset($ARRAY[$j]{'options'})){$ITEM{'options'} = $ARRAY[$j]{'options'}; } if (isset($ARRAY[$j]{'value_options'})){$ITEM{'value_options'} = $ARRAY[$j]{'value_options'}; } $ITEM{'value'} = (isset($ARRAY[$j]{'value'}) && $ARRAY[$j]{'value'}) ? $ARRAY[$j]{'value'} : ' '; $ITEM{'comments'} = (isset($ARRAY[$j]{'comments'}) && $ARRAY[$j]{'comments'}) ? $ARRAY[$j]{'comments'} : ' '; if (isset($ARRAY[$j]{'not_null'})){$ITEM{'notnull'} = $ARRAY[$j]{'not_null'};} elseif ($notnull_record) {$ITEM{'not_null'} = 1;} else {$ITEM{'notnull'} = 0;} if (!empty($GROUP) && in_array($ITEM{'name'},$VALUES)) { $ITEM{'not_null'} = not_null_field_in_group($PARAMS,$GROUP); } if (isset($ARRAY[$j]{'used_for'}) && $ARRAY[$j]{'used_for'}){$ITEM{'used_for'} = $ARRAY[$j]{'used_for'};} $FIELDS[] = $ITEM; } } return $FIELDS; } #::::::::::::::::::::::::::::::::::: function not_null_field_in_group($PARAMS,$GROUP) { $not_null = 0; $number = count($GROUP); if ($number) { # add table name and record's number to the field name $GROUPS = add_table_and_record($GROUP); for ($i=0; $i<$number; $i++) { $NEW = array(); if (isset($PARAMS{$GROUPS[$i]{'name'}})) { $NEW = (is_array($PARAMS{$GROUPS[$i]{'name'}})) ? $PARAMS{$GROUPS[$i]{'name'}} : array($PARAMS{$GROUPS[$i]{'name'}}) ; $number_multiple = count($NEW); for ($j=0; $j<$number_multiple; $j++) { if (trim($NEW[$j])) { $not_null = 1; break; } } if ($not_null== 1){break;} } } } return $not_null; } #::::::::::::::::::::::::::::::::::: function site_www($name,$url,$new_window=0,$mouse_event='',$class='') { $string = $name; if ($name && $url) { $url = corrected_www($url); $target = ($new_window) ? ' target="_blank" ' : ' '; if ($class){$class = ' ' . $class;} if ($mouse_event){$mouse_event = ' ' . $mouse_event;} $string = '' . $name . ''; } return $string; } #::::::::::::::::::::::::::::::::::: function form_value_for_field($ARRAY) { $print_name = 'form_value_for_field'; $string = ''; # $ARRAY: 'name'=>; 'table'=>; 'record'=> $field_name = add_table_and_record_to_field($ARRAY); if (isset($_SESSION{$field_name})){$string = $_SESSION{$field_name}; } if (isset($_POST{$field_name})){$string = $_POST{$field_name}; } return $string; } #::::::::::::::::::::::::::::::::::: function clean_empty_space($string) { $string = trim($string); while(strstr($string,' ')) { $string = str_replace(' ',' ',$string); } return $string; } #::::::::::::::::::::::::::::::::::: function make_replacements($ARRAY,$REPLACE) { $print_name = 'make_replacements'; if (!empty($ARRAY) && !empty($REPLACE)) { foreach ($REPLACE as $replace_key => $replace_value) { foreach ($ARRAY as $key => $value) { if (!is_array($value) && $value && strstr($value,$replace_key)) { $ARRAY{$key} = str_replace($replace_key,$replace_value,$value); } } } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function value_for_alias($name='',$table='Alias') { $print_name = 'value_for_alias'; $ARRAY = array(); $string = ''; $QUERY = array( 'tables' => $table, 'fields' => 'Name,Value,Used_From_Function,Type', 'where' => 'Status="active"', ); if ($name){$QUERY{'where'} .= ' and Name="' . $name . '"';} $DATA = select_data($QUERY,array(),0); $number = count($DATA); for ($i=0; $i<$number; $i++) { if (strtolower($DATA[$i]{'Type'})=='function') { $eval_string = '$ARRAY{$DATA[$i]{\'Name\'}} = ' . $DATA[$i]{'Value'} . ';'; eval($eval_string); } else {$ARRAY{$DATA[$i]{'Name'}} = $DATA[$i]{'Value'} ;} } if ($name) { $string = (isset($ARRAY{$name})) ? $ARRAY{$name} : ''; # replace ALIAS if there are any in ALIAS if (is_array($string)) { $NEW = $string; $type_array = 1; } else { $NEW[] = $string; $type_array = 0; } if (!empty($NEW)) { foreach ($NEW as $key => $value) { if (!is_array($value)) { $ALIAS = alias_array($value,$table); if (!empty($ALIAS)) { foreach ($ALIAS as $key_alias => $value_alias) { $ITEM = array('string'=>$value); $ITEM = make_replacements($ITEM,$ALIAS); } $NEW{$key} = $ITEM{'string'}; } } } } $string = ($type_array) ? $NEW : $NEW[0] ; return $string; } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function create_identity() { $print_name = 'create_identity'; global $FORM,$PARAMS; # form with session if (isset($FORM{'session'}) && $FORM{'session'} && isset($_SESSION) && !$_SESSION{'identity'}) # create identity { $ARRAY = array(); if ($_SERVER{'REMOTE_ADDR'}){$ARRAY[] = $_SERVER{'REMOTE_ADDR'};} if ($_SESSION{'session_id'}){$ARRAY[] = $_SESSION{'session_id'};} if ($_SESSION{'security_code'}){$ARRAY[] = $_SESSION{'security_code'};} $ARRAY[] = time(); $_SESSION{'identity'} = implode($ARRAY,'-'); return $_SESSION{'identity'}; } else # no session { $identity_field = (isset($FORM{'field_identity'}) && $FORM{'field_identity'}) ? $FORM{'field_identity'} : 'Identity'; $table = $FORM{'connection'}{'main_table'}; $identity_create = 1; $identity_value = ''; $field_name = add_table_and_record_to_field(array('name'=>$identity_field,'table'=>$table)); if (isset($PARAMS{$field_name}) && $PARAMS{$field_name}) { $identity_value = $PARAMS{$field_name}; $identity_create = is_value_exists($identity_field,$identity_value,$table); } if ($identity_create) # create/re-create IDENTITY { if (isset($PARAMS)){$PARAMS = array();} $_POST = array(); if (!isset($FORM{'random_chars'})){$FORM{'random_chars'} = 10;} $identity_value = create_identity_value($FORM{'random_chars'},1); } $FIELDS = $FORM{'fields'}{'fields'}; $number = count($FIELDS); for ($i=0; $i<$number; $i++) { if (isset($FIELDS[$i]{'name'}) && $FIELDS[$i]{'name'}==$identity_field && isset($FIELDS[$i]{'table'}) && $FIELDS[$i]{'table'}==$table) { $FORM{'fields'}{'fields'}[$i]{'value'} = $identity_value; break; } } } } #::::::::::::::::::::::::::::::::::: function select_data($QUERY,$CONNECT_OWN=array(),$untrusted_data=1) { $print_name = 'select_data'; $array = select_query($QUERY,'','html',$CONNECT_OWN); $number = count($array); # replace bad for me characters $BAD = array( "\xe2\x80\x9a" => ",", "\xc6\x92" => "f", "\xe2\x80\xa6" => "...", "\xe2\x80\x98" => "'", "\xe2\x80\x99" => "'", "\xe2\x80\x9c" => '"', "\xe2\x80\x9d" => '"', "\xe2\x80\x93" => "-", "\xe2\x80\x94" => "-", "\xcb\x9c" => "~", ); if ($untrusted_data) # clean untrusted data { for ($i=0; $i<$number; $i++) { foreach ($array[$i] as $key => $value) { if (is_string($value) && $key!='File' && !stristr($key,'_File') && $key!='Image' && !stristr($key,'_Image')) { $value = clean_untrusted_string($value); $array[$i]{$key} = $value; } } } } return $array; } #::::::::::::::::::::::::::::::::::: function check_submission($field_name,$field_value,$table) { global $FORM; $resubmit = 1; $QUERY = array( 'tables' => $table, 'fields' => $field_name, 'where' => $field_name . '="' . $field_value. '"', ); $DATA = select_data($QUERY); if (count($DATA)==1){$resubmit = 0; } return $resubmit; } #::::::::::::::::::::::::::::::::::: function directory_for_writing($file_path) { $print_name = 'directory_for_writing'; $PATH = explode('/',$file_path); $number = count($PATH) -1; $current = ''; for ($i=0; $i<$number; $i++) { $path_element = $PATH[$i]; if ($i) {$path_element = '/' . $path_element ;} $current .= $path_element; if (preg_match("/[0-9a-z]/i",$PATH[$i])) { break;} } create_directory_for_writing($current); $dirs = str_replace($current,'',$file_path); $DIRS = explode('/',$dirs); $number = count($DIRS) - 1; for ($i=1; $i<$number; $i++) { $current .= '/' . $DIRS[$i]; create_directory_for_writing($current); } return $current; } #::::::::::::::::::::::::::::::::::: function copy_file($file_source, $file, &$NON_EXIST) { $print_name = 'copy_file'; $ok = 0; if (is_file($file_source)) { $ok = copy($file_source, $file); } else { $FILE = explode('/',$file); $number = count($FILE) - 1; $file = $FILE[$number]; $NON_EXIST[] = $file; } return $ok; } #::::::::::::::::::::::::::::::::::: function clean_form_data(&$PARAMS) { $print_name = 'clean_form_data'; if (!empty($PARAMS)) { foreach ($PARAMS as $key => $value) { if (is_array($value)) { $number = count($value); for ($i=0; $i<$number; $i++) { $value[$i] = clean_data($value[$i]); } } else { $value = clean_data($value); } $PARAMS{$key} = $value; } } } #::::::::::::::::::::::::::::::::::: function forced_to_be_empty(&$ARRAY,$FORCED) { $print_name = 'forced_to_be_empty'; if (!empty($FORCED)) { foreach ($FORCED as $key => $VALUE) { $table = $key; $number = count($VALUE); for ($i=0; $i<$number; $i++) { $main_field = $VALUE[$i]{'main'}; $MAIN_VALUES = (isset($VALUE[$i]{'main_values'})) ? $VALUE[$i]{'main_values'} : array(''); if (!is_array($MAIN_VALUES)){$MAIN_VALUES = array($MAIN_VALUES);} if (!isset($VALUE[$i]{'record'}) || empty($VALUE[$i]{'record'})){$VALUE[$i]{'record'} = array(1);} $FIELDS = $VALUE[$i]{'forced'}; $number_fields = count($FIELDS); if ($number_fields) { $number_records = count($VALUE[$i]{'record'}); for ($j=0; $j<$number_records; $j++) { $record = $VALUE[$i]{'record'}[$j]; $name_main = add_table_and_record_to_field(array('name'=>$main_field,'table'=>$table,'record'=>$record)); if (isset($ARRAY{$name_main}) && in_array(trim($ARRAY{$name_main}),$MAIN_VALUES)) { for ($k=0; $k<$number_fields; $k++) { $name_field = add_table_and_record_to_field(array('name'=>$FIELDS[$k],'table'=>$table,'record'=>$record)); if (isset($ARRAY{$name_field}) && $ARRAY{$name_field}){$ARRAY{$name_field} = '';} } } } } } } } } #::::::::::::::::::::::::::::::::::: function pick_date_fields($PARAMS,$change=1) { $print_name = 'pick_date_fields'; global $PARAMS; # function chooses all date elements from assos array and forms from them appropriate date field $ARRAY = array('year','month','day','hour','min','sec'); $J = 0; $FIELDS = array(); $NEW = array(); if (is_array($PARAMS) && !empty($PARAMS)) { $number = count($ARRAY); foreach($PARAMS as $key => $value) { for($i=0; $i<$number; $i++) { $not_add = 0; if (strstr($key,'|' . $ARRAY[$i])) { list($field,$date_time) = explode('|',$key); for ($j=0; $j $value) { for ($j=0; $j<$number;$j++) { if ($key == $ARRAY[$j]) { $ELEMENT[] = strtoupper($key) . ':' . $value; break; } } } if ($change) { $PARAMS{$FIELDS[$i]{'name'}} = (!empty($ELEMENT)) ? implode($ELEMENT,'|'): ''; } $NEW{$FIELDS[$i]{'name'}} = $PARAMS{$FIELDS[$i]{'name'}}; } } return $NEW; } #::::::::::::::::::::::::::::::::::: function correction_date_time(&$ARRAY) { $print_name = 'correction_date_time'; # function changes date format and returns array of wrong fields (if any) $WRONG = array(); if (count($ARRAY)) { foreach ($ARRAY as $key => $value) { if (strstr($key,'Date') || strstr($key,'Time')) { if (!is_array($value) && (strstr($value,'|') || strstr($value,':') || !$value)) { $ARRAY{$key} = convert_date_string($value,$key); } if (preg_match('/[a-z]/i',$ARRAY{$key})) { $WRONG[] = $key; } } } foreach ($ARRAY as $key => $value) { if (preg_match('/\*$/',$key)) { unset($ARRAY{$key}); $key = preg_replace('/\*$/','',$key); $ARRAY{$key} = $value; } } for ( $i=0; $i $value) { $wrong = 0; if ((stristr($key,'email') || stristr($key,'e-mail') || stristr($key,'e_mail')) && $value) { if (!strstr($value,'@') || $value=='@') { $wrong = 1; } else { $ITEMS = find_email($value); $number = count($ITEMS); if (!$number){$wrong = 1;} } if ($wrong){$ARRAY[] = $key;} } } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function add_table_and_record($ARRAY) { $number = count($ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ARRAY[$i]{'name'}) && $ARRAY[$i]{'name'} && isset($ARRAY[$i]{'table'}) && $ARRAY[$i]{'table'}) { $field_name = $ARRAY[$i]{'name'}; $ARRAY[$i]{'name'} = add_table_and_record_to_field($ARRAY[$i]); } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function submitter_name($FIELDS_ALL,$PARAMS,$SESSION=array()) { $string = ''; # find submitter fields $number = count($FIELDS_ALL); $SUBMITTER = array(); for ($i=0; $i<$number; $i++) { if (isset($FIELDS_ALL[$i]{'submitter'}) && $FIELDS_ALL[$i]{'submitter'}){$SUBMITTER[] = $FIELDS_ALL[$i]; } } # find submitter values $number = count($SUBMITTER); $ARRAY = array(); for ($i=0; $i<$number; $i++) { $field_name = $SUBMITTER[$i]{'name'}; $FIELD = add_table_and_record(array($SUBMITTER[$i])); $full_field_name = $FIELD[0]{'name'}; $session_name = (isset($SESSION{$full_field_name})) ? $SESSION{$full_field_name} : ''; $ARRAY{$SUBMITTER[$i]{'submitter'}} = (isset($PARAMS{$full_field_name}) && $PARAMS{$full_field_name}) ? $PARAMS{$full_field_name} : $session_name ; } if (is_array($ARRAY) && !empty($ARRAY)) { $string = get_name($ARRAY); } if (!$string){$string = 'Colleague';} return $string; } #::::::::::::::::::::::::::::::::::: function clean_untrusted_string($string) { if ($string) { $string = htmlspecialchars($string); $string = str_replace('/','/',$string); } return $string; } #::::::::::::::::::::::::::::::::::: function text_vs_html($string,$page_type='html',$li_alt_for_pdf='*') { $print_name = 'text_vs_html'; if ($page_type!='html') { if ($li_alt_for_pdf){$li_alt_for_pdf = ' ' . $li_alt_for_pdf . ' ';} $string = trim($string); $string = str_replace("''",'"',$string); $string = str_replace(array('
','
'),"
",$string); $string = str_replace(array('
','
'),"\n",$string); $string = str_replace(' ',' ',$string); $string = str_replace('&','&',$string); $string = str_replace('<','<',$string); $string = str_replace('>','>',$string); $string = str_replace('/','/',$string); $string = str_replace(array('','','',''),'',$string); $string = str_replace(array('',' '),'',$string); $string = str_replace(array('','','',' '),'',$string); $string = str_replace(array('
  • ','
  • ','
  • '),"\n" . $li_alt_for_pdf ,$string); # strip unwanted tags $string = strip_single('a',$string); # remove only tag - content should stay $string = strip_single('span',$string); # remove only tag - content should stay $string = strip_single('p',$string); # remove only tag - content should stay $string = strip_single('ul',$string); # remove only tag - content should stay $string = strip_single('ol',$string); # remove only tag - content should stay $string = str_replace(array("\r ","\n "),array("\r","\n"),$string); $string = str_replace("\r\n","\n",$string); } else { if ($string) { # lists $string = str_replace(array("\r
  • ","\r
  • "),'
  • ',$string); $string = str_replace(array("
      \r","
        \r "),'
          ',$string); $string = str_replace(array("\r
        ","\r
      "),'
    ',$string); $string = str_replace(array("
      \r","
        \r "),'
          ',$string); $string = str_replace(array("\r
        ","\r
      "),'
    ',$string); # new line $string = str_replace(array("\n\r","\r\n"),"\r",$string); $string = str_replace(array("\n","\r"),'
    ',$string); } else {$string = '';} } $string = trim($string); return $string; } #::::::::::::::::::::::::::::::::::: function handel_uploaded_files(&$ARRAY,&$FIELDS_ALL,$upload_directory='upload',$root='') { $print_name = 'handel_uploaded_files'; $FILES = (isset($_FILES)) ? $_FILES : array() ; $number = count($FIELDS_ALL); # 1MB definition $mb = 1024*1024; # max size for UPLOAD by server $max_upload_size = min(let_to_num(ini_get('post_max_size')), let_to_num(ini_get('upload_max_filesize'))); $WRONG = array(); $NOT_NULL = array(); if (!empty($FIELDS_ALL)) { $NOT_NULL = find_by_property_array($FIELDS_ALL,'not_null',1); if (!empty($NOT_NULL)){$NOT_NULL = select_property($NOT_NULL,'name');} } # pick all uploaded files $NEW = array(); if (is_array($ARRAY) && !empty($ARRAY)) { foreach ($ARRAY as $key => $value) { if (strstr($key,'_File')) { $NEW{$key} = $value; if ($value=='to_reupload') # if file needs to be re-uploaded { $value = ''; $ARRAY{$key} = $value; if (!isset($WRONG{'to_reupload'})){$WRONG{'to_reupload'} = array();} $ITEM = find_by_property($FIELDS_ALL,'name',$key); $WRONG{'to_reupload'}[] = $ITEM; } if (!$value && in_array($key,$NOT_NULL)) # check against not_null requirement { if (!isset($WRONG{'empty'})){$WRONG{'empty'} = array();} $ITEM = find_by_property($FIELDS_ALL,'name',$key); $WRONG{'empty'}[] = $ITEM; } } } } if (is_array($FILES) && !empty($FILES)) # there are uploaded files { if(!isset($_SESSION{'uploaded_names'})) {$_SESSION{'uploaded_names'} = array();} $USER_NAME = array(); # check file fields vs uploaded files if (!empty($NEW)) { foreach ($NEW as $key => $value) { if (isset($FILES{$value})) { $upload_ok = 0; $UPLOAD = $FILES{$value}; $FIELD = find_by_property($FIELDS_ALL,'name',$key); # EXTENSION $ext = file_ext($UPLOAD{'name'}); $original_name = string_to_url(file_name($UPLOAD{'name'})); if (!$original_name){$original_name = 'original';} $original_name .= '.' . string_to_url($ext); # UNIX type $filetype_unix = filetype_unix($UPLOAD{'tmp_name'}); $original_size = round($UPLOAD{'size'}/$mb,2) . 'MB'; for ($i=0; $i<$number; $i++) { if (isset($FIELDS_ALL[$i]{'name'}) && $key==$FIELDS_ALL[$i]{'name'}) { $FIELDS_ALL[$i]{'file_property'} = array( 'name' => $original_name, 'size' => $original_size, 'format' => $filetype_unix, ) ; break; } } if (isset($FIELD{'file_size'}) && $FIELD{'file_size'} && $FIELD{'file_size'}*$mb<$max_upload_size) # upload size defined by form { $size_for_upload = $FIELD{'file_size'}*$mb ; } else # upload size defined by server { $size_for_upload = $max_upload_size ; } if (!$UPLOAD{'name'} || !$UPLOAD{'size'} || !$UPLOAD{'tmp_name'} || $UPLOAD{'error'}) # empty upload { $ARRAY{$key} = ''; if (isset($FIELD{'not_null'}) && $FIELD{'not_null'}) { if (!isset($WRONG{'empty'})){$WRONG{'empty'} = array();} $WRONG{'empty'}[] = $FIELD; } } elseif ($UPLOAD{'size'}>$size_for_upload) # very big uploaded file { # in MB $ARRAY{$key} = ''; if (!isset($WRONG{'size'})){$WRONG{'size'} = array();} $FIELD{'error'} = 'size of "' . $original_name . '" (' . $original_size . ') > than allowed size (' . number_format($size_for_upload/$mb,2) . 'MB)'; $WRONG{'size'}[] = $FIELD; } else # check file FORMAT { $FORMAT_TYPE = explode(' ',$filetype_unix); $filetype_unix = $FORMAT_TYPE[0]; if (isset($FIELD{'file_format'}) && is_array($FIELD{'file_format'}) && !empty($FIELD{'file_format'})) { if (in_array(strtolower($filetype_unix),$FIELD{'file_format'})) { $upload_ok = 1; } else # NOT allowed format { $ARRAY{$key} = ''; if (!isset($WRONG{'format'})){$WRONG{'format'} = array();} $FIELD{'error'} = 'the submitted "' . $original_name . '" document has not been recognized as a ' . implode($FIELD{'file_format'},', or ') . ' document. Please submit a ' . implode($FIELD{'file_format'},', or ') . ' document.'; $WRONG{'format'}[] = $FIELD; } } else { $upload_ok = 1; } if ($upload_ok ) { $NON = array(); $ARRAY{$key} = $UPLOAD{'name'}; $upload_ok = is_uploaded_file($UPLOAD{'tmp_name'}); if ($upload_ok ) { if ($upload_directory && substr($upload_directory,-1,1)!='/'){$upload_directory .= '/';} $file_path = $upload_directory . str_replace('/','',strrchr($UPLOAD{'tmp_name'},'/')) . strrchr($UPLOAD{'name'},'.') ; $file_path_from_root = $root . $file_path; directory_for_writing($file_path_from_root); $upload_ok = copy_file($UPLOAD{'tmp_name'}, $file_path_from_root, $NON); } if ($upload_ok) { $ARRAY{$key} = $file_path . '|' . $original_name; unlink($UPLOAD{'tmp_name'}); } else {$ARRAY{$key} = ''; } } } } } } } return $WRONG; } #::::::::::::::::::::::::::::::::::: function add_user_file_name(&$ARRAY,$NAMES) { if (is_array($NAMES) && !empty($NAMES)) { $number = count($ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ARRAY[$i]{'name'}) && $ARRAY[$i]{'name'} && isset($NAMES{$ARRAY[$i]{'name'}}) && $NAMES{$ARRAY[$i]{'name'}}){$ARRAY[$i]{'file_user'} = $NAMES{$ARRAY[$i]{'name'}}; } } } } #::::::::::::::::::::::::::::::::::: function steps_number(&$ARRAY) { $number = count($ARRAY); $number_steps = 0; if ($number) { for ($i=0; $i<$number; $i++) { if (!isset($ARRAY[$i]{'step'}) || !$ARRAY[$i]{'step'}){$ARRAY[$i]{'step'} = 1;} } $number_steps = max(select_property($ARRAY,'step')); } return $number_steps; } #::::::::::::::::::::::::::::::::::: function processing_steps($ARRAY,&$current_step,$number_steps,&$security_field,&$submit_button,&$security_status,$extra_step_field='') { $print_name = 'processing_steps'; global $PARAMS, $CONNECTION, $FORM; $NEW = array(); $verify_at_end = (isset($FORM{'verify_at_end'})) ? $FORM{'verify_at_end'} : 0 ; if ($number_steps) { # if security is needed if (isset($FORM{'security_field'}) && $FORM{'security_field'}) { # security if ($FORM{'session'} && !isset($_SESSION{'security_ok'}) && !$_SESSION{'security_ok'}) # form did not pass though security yet { $security_field = $FORM{'security_field'}; $security_status = check_security_field($security_field); if ($security_status!='ok') { $current_step = 1; # add security field $NEW = fields_for_security_image($security_field,$FORM{'security_path'},$FORM{'layout'}{'size'}{'cols'}); } } } $NEW_FORM = array(); # EXTRA steps if needed if ($current_step>$number_steps)# fields array for EXTRA step if there is expired uploaded file { if (!$extra_step_field) { $extra_step_field = extra_step_field_name($PARAMS,$ARRAY); } if ($extra_step_field) { $NEW_FORM = find_by_property_array($ARRAY,'name',$extra_step_field); $verify_step = $NEW_FORM[0]{'step'}; } elseif (!$verify_at_end) {$current_step = 1;} } if ($current_step<=$number_steps) # MAIN form steps { # find all fields for current step form $NEW_FORM = array(); $number_fields = count($ARRAY); for ($i=0; $i<$number_fields; $i++) { if ($ARRAY[$i]{'step'}==$current_step) { $NEW_FORM[] = $ARRAY[$i]; } } $number_fields_for_step = 0; $number = count($NEW_FORM); for ($i=0; $i<$number; $i++) { if (isset($NEW_FORM[$i]{'name'}) && $NEW_FORM[$i]{'name'}){$number_fields_for_step = 1; break;} } if (!$number_fields_for_step) { $current_step++; if ($current_step<=$number_steps) { $NEW_FORM = find_by_property_array($ARRAY,'step',$current_step); } } } elseif ($verify_at_end || stristr($PARAMS{'submit'},'save')) { $NEW_FORM = $ARRAY; } if (isset($PARAMS{'submit'}) && stristr($PARAMS{'submit'},'save')) # all fields for saved submission { $NEW_FORM = $ARRAY; } $NEW = array_merge($NEW_FORM,$NEW); # set value for form element from POST array set_values($NEW,$PARAMS); # if there is a database to put the data then change text field length according to the length of the fields in the database DOES IT WORK ????? if (isset($CONNECTION{'table'}) && $CONNECTION{'table'}) { $NEW = change_field_length($NEW); } $verify_step = (isset($verify_step)) ? $verify_step : ''; # to add verification $NEW = array_merge($NEW,extra_fields_for_step($ARRAY,$current_step,$number_steps,$submit_button,$verify_step)); } return $NEW; } #::::::::::::::::::::::::::::::::::: function alert_field_property($FIELDS,$WRONG) { # function adds alert property to the form field attributes $print_name = 'alert_field_property'; $number = count($FIELDS); for ($i=0; $i<$number; $i++) { # select only actual form fields if (isset($FIELDS[$i]{'name'}) && $FIELDS[$i]{'name'} && (strtolower($FIELDS[$i]{'type'})!='hidden' || strtolower($FIELDS[$i]{'type'})!='info')) { if (in_array($FIELDS[$i]{'name'},$WRONG)) # WRONG value in the field { $FIELDS[$i]{'alert'} = 1; } elseif (isset($FIELDS[$i]{'not_null'}) && $FIELDS[$i]{'not_null'}) # EMPTY required field { if (!isset($FIELDS[$i]{'value'}) || !trim($FIELDS[$i]{'value'})) { $FIELDS[$i]{'alert'} = 1; } } } } return $FIELDS; } #::::::::::::::::::::::::::::::::::: function all_form($FIELDS,$action,$SIZE=array(),$submit_button='Submit',$hr=1,$security_field='',$form_name='',$button_position='bottom',$save_submission='') { $print_name = 'all_form'; $form = ''; # empty security field if ($security_field) { $FIELDS = empty_security_field($security_field,$FIELDS); } $upload = upload_required($FIELDS{'fields'}); # if user's verification is required: $submit_button = 'Continue' if (!empty($FIELDS{'fields'})) { $data = form($FIELDS{'fields'},'','',$SIZE,$FIELDS{'table_cols'},$FIELDS{'align'}); if ($data) { if ($hr) { $data .= '
    '; } if ($save_submission) { $save_submission = ''; } $button = '
    ' . $save_submission . '
    '; if ($button_position=='top'){$data = $button . $data ;} else {$data .= $button;} $name = ($form_name) ? ' name="' . $form_name . '"' : ''; $form = '
    '; $form .= $data; $form .= '
    '; } } return $form; } #::::::::::::::::::::::::::::::::::: function empty_form_fields($FIELDS) { $print_name = 'empty_form_fields'; # for string and text fields NOT for upload file fields $EMPTY = array(); $number = count($FIELDS); for ($i=0; $i<$number; $i++) { if (isset($FIELDS[$i]{'not_null'}) && $FIELDS[$i]{'not_null'} && $FIELDS[$i]{'type'}!='File' && (!isset($FIELDS[$i]{'value'}) || !$FIELDS[$i]{'value'} || !preg_match('/[a-z0-9]/i',$FIELDS[$i]{'value'}))) { $EMPTY[] = $FIELDS[$i]; } } return $EMPTY; } #::::::::::::::::::::::::::::::::::: function select_property($ASS_ARRAY,$property_name) { $print_name = 'select_property'; $ARRAY = array(); if (isset($ASS_ARRAY[0]{$property_name})) { $number = count($ASS_ARRAY); for ($i=0; $i<$number; $i++) { $ARRAY[$i] = $ASS_ARRAY[$i]{$property_name}; } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function field_title_by_name($ARRAY,$ATT) { $NEW = array(); $ITEM = array(); $number = count($ATT); for ($i=0; $i<$number; $i++) { $NEW[] = find_by_property($ARRAY,'name',$ATT[$i]); } if (!empty($NEW)){$ITEM = select_property($NEW,'title');} return $ITEM; } #::::::::::::::::::::::::::::::::::: function status_for_wrong_fields($ARRAY,&$status,$SPECIAL=array()) { $string = ''; # $SPECIAL => fields with special wrong message (somethig like: 'This Login is already in use. Please choose another one.') $NEW = $SPECIAL; if (is_array($ARRAY) && !empty($ARRAY)) { foreach($ARRAY as $key => $value) { if (isset($value{'fields'}) && is_array($value{'fields'}) && !empty($value{'fields'})) { $NEW[] = $value{'message'} . ' ' . implode($value{'fields'},', '); } } } if (!empty($NEW)) { $status = 1; $string = implode($NEW,'
    '); } return $string; } #::::::::::::::::::::::::::::::::::: function set_values(&$FIELDS,$PARAMS,$upload=0) { $print_name = 'set_values'; # set value for form element from POST array if (isset($PARAMS) && !empty($PARAMS)) { $KEYS = array_keys($PARAMS); $number_fields = count($FIELDS); for ($i=0; $i<$number_fields; $i++) { if (!$upload && isset($FIELDS[$i]{'type'}) && strtolower($FIELDS[$i]{'type'})=='checkboxset' && !isset($PARAMS{$FIELDS[$i]{'name'}})) { $PARAMS{$FIELDS[$i]{'name'}} = ''; } foreach ($PARAMS as $key => $value) { if (isset($FIELDS[$i]{'name'}) && $FIELDS[$i]{'name'} == $key) { if (is_array($value)){$value = implode(';',$value);} $FIELDS[$i]{'value'} = $value; break; } } } } } #::::::::::::::::::::::::::::::::::: function all_info($FIELD,$root='') { $print_name = 'all_info'; # function shows all form data as a HTML table $table = ''; $number_fields = count($FIELD); for ($i=0; $i<$number_fields; $i++) { # omit HIDDEN fields for a report if (isset($FIELD[$i]{'text'}) && $FIELD[$i]{'text'}) { $text_string = $FIELD[$i]{'text'}; $text_class = ''; if (isset($FIELD[$i]{'class'}) && $FIELD[$i]{'class'}) { $text_class = ' class="' . $FIELD[$i]{'class'} . '"'; $text_string = '' . $text_string . ''; } $table .= '' . $text_string . ''; } elseif (isset($FIELD[$i]{'type'}) && !stristr($FIELD[$i]{'type'},'hidden') && !stristr($FIELD[$i]{'type'},'password') && !stristr($FIELD[$i]{'type'},'button')) { { $value = (isset($FIELD[$i]{'value'})) ? $FIELD[$i]{'value'} : ''; if (isset($FIELD[$i]{'options'})) { selected_field_value($FIELD[$i]); # correct value for selected fields $value = (isset($FIELD[$i]{'value'})) ? $FIELD[$i]{'value'} : ''; if ($value && strtolower($FIELD[$i]{'type'})=='checkboxset') { $value = str_replace('; ',';',$value); $value = show_list(explode(';',$value)); } } else { # date if (strstr($value,'.') && (strstr($FIELD[$i]{'name'},'Date') || strstr($FIELD[$i]{'title'},'Date'))) { $value = event_dates($value); } # uploaded files elseif ($FIELD[$i]{'type'}=='File') { if ($value) { $FILE_ITEM = (isset($FIELD[$i]{'tmp_value'}) && $FIELD[$i]{'tmp_value'}) ? explode('|',$FIELD[$i]{'tmp_value'}) : explode('|',$value); $link_name = $FILE_ITEM[0]; # if there is $_SESSION if (isset($FIELD[$i]{'file_user'}) && $FIELD[$i]{'file_user'}) {$link_name = $FIELD[$i]{'file_user'};} # with/without $_SESSION if (isset($FILE_ITEM[1]) && $FILE_ITEM[1]) {$link_name = $FILE_ITEM[1];} $link_name = file_name_and_ext($link_name); $value = 'attached: ' . site_www($link_name,$root . $FILE_ITEM[0],1) ; } else { $value = 'NONE attached'; } } else { $value = clean_untrusted_string($value); $value = text_vs_html($value,'html'); } } if(!$FIELD[$i]{'title'}) {$FIELD[$i]{'title'} = ucfirst(str_replace('_',' ',$FIELD[$i]{'name'}));} $table .= ' ' . $FIELD[$i]{'title'} . ' ' . $value . ''; } } } if ($table) { $table = '
    ' . $table . '

    '; } return $table; } #::::::::::::::::::::::::::::::::::: function drop_security_fields($ARRAY) { $number = count($ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ARRAY[$i]{'security'}) && $ARRAY[$i]{'security'}){unset($ARRAY[$i]);} } $NEW = array_values($ARRAY); return $NEW; } #::::::::::::::::::::::::::::::::::: function find_by_property($ASS_ARRAY,$property_name,$property_value) { $print_name = 'find_by_property'; $ARRAY = array(); $number = count($ASS_ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ASS_ARRAY[$i]{$property_name}) && $ASS_ARRAY[$i]{$property_name}==$property_value) { $ARRAY = $ASS_ARRAY[$i]; break; } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function hidden_form($FIELD,$action,$submit_button='Finish',$save_submission='',$return_button=1) { $data = ''; $number_fields = count($FIELD); for ($i=0; $i<$number_fields; $i++) { $array = array(); if (isset($FIELD[$i]{'value'}) && strtolower($FIELD[$i]{'type'})!='button') { if (stristr($FIELD[$i]{'type'}, 'multiple')) { $array = explode(',',$FIELD[$i]{'value'}); $number_array = count($array); for ($k=0; $k<$number_array; $k++) { $data .= ''; } } else {$data .= '';} } } $return_button = ($return_button) ? '' : ''; $submit_button = '   '; if ($save_submission) { $save_submission = '   '; } $data .= '
    ' . $return_button . $save_submission . $submit_button . '
    '; $data = '
    ' . $data . '
    '; return $data; } #::::::::::::::::::::::::::::::::::: function put_values_into_session($ARRAY) { global $_SESSION; $number = count($ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ARRAY[$i]{'value'}) && $ARRAY[$i]{'value'}){$_SESSION{$ARRAY[$i]{'name'}} = $ARRAY[$i]{'value'}; } } } #::::::::::::::::::::::::::::::::::: function check_expired_upload_files($FIELDS_ALL,$root) { $EXPIRED = array(); $ARRAY = find_by_property_array($FIELDS_ALL,'type','File'); $REMOVED = array(); $EXPIRED = array(); $number = count($ARRAY); for ($i=0; $i<$number; $i++) { $upload_file = $ARRAY[$i]{'value'}; if ($upload_file) { $FILE_ITEM = explode('|',$upload_file); $file_path_from_root = $root . $FILE_ITEM[0] ; if (is_file($file_path_from_root)) # change modification time for needed file to current time (to avoid removing this file) { } else # file already removed!! { $REMOVED[] = $ARRAY[$i]; } } } if (!empty($REMOVED)) { sort_by_colomn($REMOVED,'step'); $EXPIRED = $REMOVED[0]; } return $EXPIRED; } #::::::::::::::::::::::::::::::::::: function working_with_uploaded_files(&$ARRAY,$directory_depot='depot',$version_separator='__',$UPLOAD_NAMING=array(),$root='') { global $PAGE; $print_name = 'working_with_uploaded_files'; # pick up upload fields $NEW = find_by_property_array($ARRAY,'type','File'); $ITEMS = data_from_database_for_uploaded_names($NEW,$UPLOAD_NAMING); $number_fields = count($ARRAY); # add extra path for aside UPDATE website $from_update_to_real_website = (isset($PAGE{'data'}{'from_update_to_real_website'}) && $_SERVER{'SERVER_NAME'}!='localhost') ? $PAGE{'data'}{'from_update_to_real_website'} : ''; $number = count($NEW); for ($i=0; $i<$number; $i++) { if(isset($NEW[$i]{'value'}) && $NEW[$i]{'value'}) { if (strstr($NEW[$i]{'value'},'|')) { $FILE_ITEM = explode('|',$NEW[$i]{'value'}); $file_source_path = $FILE_ITEM[0]; $file_source = $root . $file_source_path; if(is_file($file_source)) # file exists { $ext = file_ext($file_source); $NAMING = (isset($NEW[$i]{'fields_naming'})) ? $NEW[$i]{'fields_naming'} : array() ; $name = creating_uploaded_file_name($NEW[$i]{'file_name'},$NAMING,$ARRAY,$ITEMS,$separator='-'); # correct file name to english symbols $name = string_to_url($name,'-'); $directory = (isset($NEW[$i]{'depot_directory'}) && $NEW[$i]{'depot_directory'}) ? $NEW[$i]{'depot_directory'} : $directory_depot; if ($directory && substr($directory,-1)!='/'){$directory .= '/';} $file_name = $directory . $name . '.' . $ext ; $file_path_from_root = $from_update_to_real_website . $root . $file_name; $file_name = write_into_directory($file_source,$file_path_from_root,$version_separator); # put name of temporaty file into the database $file_field_tmp = ''; $FILE_ATTR = explode('__',$NEW[$i]{'name'}); if (isset($FILE_ATTR[0]) && $FILE_ATTR[0]) { $file_field_tmp = $FILE_ATTR[0] . '_TMP' . strstr($NEW[$i]{'name'},'__'); if ($file_field_tmp) { for ($j=0; $j<$number_fields; $j++) { if (isset($ARRAY[$j]{'name'}) && $ARRAY[$j]{'name'}==$file_field_tmp) { $ARRAY[$j]{'value'} = $file_source_path; break; } } } } # remove $root from $file_name $file_name = str_replace($root,'',$file_name); set_values($ARRAY,array($NEW[$i]{'name'}=>$file_name),1); add_values($ARRAY,array($NEW[$i]{'name'}=>array('tmp_value'=>$NEW[$i]{'value'}))); } } } } } #::::::::::::::::::::::::::::::::::: function populate_database($CONNECTION,$DATA,&$FORM,$success=1,$submit_button='') { $print_name = 'populate_database'; global $PAGE; # put data into the database table $ESSENTIAL = (isset($FORM{'essential_fields'})) ? $FORM{'essential_fields'} : array(); $EXTRA = (isset($FORM{'extra_fields'})) ? $FORM{'extra_fields'} : array(); $OTHER_SPECIFY = (isset($FORM{'other_specify_fields'})) ? $FORM{'other_specify_fields'} : array(); $FORCED = (isset($FORM{'forced_to_empty'})) ? $FORM{'forced_to_empty'} : array(); $CRITICAL = (isset($FORM{'critical_fields'})) ? $FORM{'critical_fields'} : array(); $CURRENT_DATE = (isset($FORM{'current_date'})) ? $FORM{'current_date'} : array(); $UPDATE = array(); $attempt_table = ($success) ? '' : 'Attempt' ; # find all 'used_for' fields (that are used in webform but not in the database) $number = count($DATA); $USED = array(); for ($i=0; $i<$number; $i++) { if (isset($DATA[$i]{'used_for'}) && $DATA[$i]{'used_for'}) { $DATA[$i]{'table'} = (isset($DATA[$i]{'table'})) ? $DATA[$i]{'table'} : $CONNECTION{'main_table'}; if (!isset($USED{$DATA[$i]{'table'}})){$USED{$DATA[$i]{'table'}} = array();} if ($DATA[$i]{'table'}){$USED{$DATA[$i]{'table'}}[] = $DATA[$i]{'name'};} } } # all records for all tables $type_records = 'records'; $NEW = table_array($DATA,$CONNECTION,$type_records); $TABLES = $NEW{'tables'}; $ARRAY = $NEW{'array'}; $main_ID = 0; $ok = 1 ; $number = count($TABLES); for ($i=0; $i<$number; $i++) { $ID_field = (isset($ID_field) && $ID_field) ? $ID_field : 'ID' ; $RECORDS = array(); $RECORD{'table_name'} = $TABLES[$i]; $RELATION = (isset($ARRAY{$RECORD{'table_name'}}{'relation'})) ? $ARRAY{$RECORD{'table_name'}}{'relation'} : array(); $ITEMS = (isset($ARRAY{$RECORD{'table_name'}}{'records'})) ? $ARRAY{$RECORD{'table_name'}}{'records'} : array(); $HIDDEN = (isset($ARRAY{$RECORD{'table_name'}}{'hidden'})) ? $ARRAY{$RECORD{'table_name'}}{'hidden'} : array(); $ACCEPT_EMPTY = (isset($ARRAY{$RECORD{'table_name'}}{'accept_empty'})) ? $ARRAY{$RECORD{'table_name'}}{'accept_empty'} : array(); $ESSENTIAL_FIELDS = (isset($ARRAY{$RECORD{'table_name'}}{'essential_fields'})) ? $ARRAY{$RECORD{'table_name'}}{'essential_fields'} : array(); $CRITICAL_FIELDS = (isset($CRITICAL{$RECORD{'table_name'}})) ? $CRITICAL{$RECORD{'table_name'}} : array(); # if there are data to put if (!empty($ITEMS) && is_array($ITEMS)) { $RECORDS = array_values($ITEMS); $number_records = count($RECORDS); $RECORD{'attempt_table'} = (isset($attempt_table)) ? $attempt_table : ''; $RECORD{'used'} = (isset($USED{$RECORD{'table_name'}})) ? $USED{$RECORD{'table_name'}} : array(); $RECORD{'other_specify'} = (isset($OTHER_SPECIFY{$RECORD{'table_name'}})) ? $OTHER_SPECIFY{$RECORD{'table_name'}} : array(); $RECORD{'forced_to_empty'} = (isset($FORCED{$RECORD{'table_name'}})) ? $FORCED{$RECORD{'table_name'}} : array(); $RECORD{'extra_fields'} = (isset($EXTRA{$RECORD{'table_name'}})) ? $EXTRA{$RECORD{'table_name'}} : array(); $RECORD{'essential_fields'} = (isset($ESSENTIAL{$RECORD{'table_name'}})) ? $ESSENTIAL{$RECORD{'table_name'}} : array(); $RECORD{'critical_fields'} = $CRITICAL_FIELDS; # to put current date into the record (mostly for updating uploaded file) $RECORD{'current_date'} = (isset($CURRENT_DATE{$RECORD{'table_name'}})) ? $CURRENT_DATE{$RECORD{'table_name'}} : array(); if (!empty($RECORD{'current_date'}) && is_array($RECORD{'current_date'})) { foreach ($RECORD{'current_date'} as $key => $value) { $RECORD{'current_date'}{$key} = date($value); } $RECORD{'extra_fields'} = array_merge($RECORD{'extra_fields'},$RECORD{'current_date'}); } $RECORD{'item'} = array(); $RECORD{'record_number'} = 0; for ($j=0; $j<$number_records; $j++) { $accept_empty_record = (isset($ACCEPT_EMPTY[$j])) ? $ACCEPT_EMPTY[$j] : 0; $RECORD{'item'} = forced_to_empty($RECORDS[$j],$RECORD{'forced_to_empty'}); $RECORD{'record_number'} = $j + 1; $RECORD{'except'} = array($ID_field); # fields which not be checked when 'empty' record is checking if (!empty($HIDDEN[$j])) { $RECORD{'except'} = array_values(array_unique(array_merge($RECORD{'except'},$HIDDEN[$j]))); } # Insert Record NOT into MAIN table # add main key field for dependent table for INSERT # add main_ID value for dependeble table record if ($RECORD{'table_name'}!=$CONNECTION{'main_table'} && empty($RELATION)) # DEPENDENT table { $RECORD{'main_ID'} = $CONNECTION{'main_ID'}; if ((!isset($RECORD{'item'}{$RECORD{'main_ID'}}) || !$RECORD{'main_ID'}) && $main_ID) { $RECORD{'item'}{$CONNECTION{'main_ID'}} = $main_ID ; } } # put all '_ID' fields into $EXCEPT array (when record will be checked as 'not empty' these fields will be ignored) if (is_array($RECORD{'item'}) && !empty($RECORD{'item'})) { foreach ($RECORD{'item'} as $key => $value) { if (strstr($key,'_ID') && !in_array($key,$RECORD{'except'}) && !in_array($key,$RECORD{'critical_fields'})) { $RECORD{'except'}[] = $key; } } } if (!$success && (!isset($RECORD{'item'}{$ID_field}) || !$RECORD{'item'}{$ID_field}) && (isset($RECORD{'item'}{'Status'}) && $RECORD{'item'}{'Status'}=='new')) # put data into 'Attempt' table { $RECORD{'item'} = $submit_button; } $UPDATE = record_into_database($RECORD,$CONNECTION,$accept_empty_record,$ID_field); $record_ID = (isset($UPDATE{'record_ID'})) ? $UPDATE{'record_ID'} : 0; if ($success && $record_ID && $RECORD{'table_name'}==$CONNECTION{'main_table'}) { if (!isset($PAGE{'data'}{'success_ID'})){$PAGE{'data'}{'success_ID'} = array();} $PAGE{'data'}{'success_ID'}[] = $record_ID; } if (!$record_ID){$ok = 0; } if ($record_ID) { if ($RECORD{'table_name'}==$CONNECTION{'main_table'} && !$main_ID) # get record ID after updating MAIN table # any extra records in MAIN table will not be associated with records into any dependent tables { $main_ID = $record_ID; } elseif (!empty($RELATION)) # get record ID after updating another independent table and update relation table { $NEW = array(); $NEW{'table_name'} = $RELATION{'bound_table'}; $NEW{'attempt_table'} = $attempt_table; $NEW{'used'} = $USED{$NEW{'table_name'}}; $NEW{'extra_fields'} = $EXTRA{$NEW{'table_name'}}; $NEW{'item'} = $RELATION{'records'}[$j]; $NEW{'record_number'} = $j + 1; $NEW{'item'}{$CONNECTION{'main_ID'}} = $main_ID ; $NEW{'item'}{$RELATION{'key'}} = $record_ID ; $UPDATE = record_into_database($NEW,$CONNECTION,'Insert',$check_empty_record=0); $record_ID = (isset($UPDATE{'record_ID'})) ? $UPDATE{'record_ID'} : 0; if (!$record_ID){$ok = 0; } } } } } } $FORM{'changes'} = $UPDATE; return $main_ID; } #::::::::::::::::::::::::::::::::::: function add_table_and_record_to_field($ARRAY) { # $ARRAY = array('name'=>"field name",'table'=>'table in which the field is','record'=>"record's number"); $string = '' ; if (isset($ARRAY{'name'}) && $ARRAY{'name'} && isset($ARRAY{'table'}) && $ARRAY{'table'}) { $ARRAY{'name'} .= '__' . $ARRAY{'table'}; if (!isset($ARRAY{'record'}) || !$ARRAY{'record'}){$ARRAY{'record'} = 1;} $ARRAY{'name'} .= '__' . $ARRAY{'record'}; $string = $ARRAY{'name'} ; } return $string; } #::::::::::::::::::::::::::::::::::: function external_fields($ARRAY) { $NEW = array(); $number = count($ARRAY); $FIELDS = array('name','title','id','value','type','text'); $number_fields = count($FIELDS); for ($i=0; $i<$number; $i++) { $ITEM = array(); for ($j=0; $j<$number_fields; $j++) { if (isset($ARRAY[$i]{$FIELDS{$j}}) && $ARRAY[$i]{$FIELDS{$j}}){$ITEM{$FIELDS{$j}} = $ARRAY[$i]{$FIELDS{$j}}; } } $NEW[] = $ITEM; } return $NEW; } #::::::::::::::::::::::::::::::::::: function form_email($FIELD) { $string = ''; $number_fields = count($FIELD); $K = 1; for ($i=0; $i<$number_fields; $i++) { selected_field_value($FIELD[$i]); # correct value for selected fields if (isset($FIELD[$i]{'name'}) && $FIELD[$i]{'name'} && strtolower($FIELD[$i]{'type'})!='hidden' && strtolower($FIELD[$i]{'type'})!='info' && strtolower($FIELD[$i]{'type'})!='button') { if (!$FIELD[$i]{'title'}){$FIELD[$i]{'title'} = ucfirst(str_replace('_',' ',$FIELD[$i]{'name'}));} else { $FIELD[$i]{'title'} = strip_tags($FIELD[$i]{'title'}); $FIELD[$i]{'title'} = str_replace('&','&',$FIELD[$i]{'title'}); $FIELD[$i]{'title'} = str_replace(' ',' ',$FIELD[$i]{'title'}); } $FIELD[$i]{'value'} = (isset($FIELD[$i]{'value'}) && $FIELD[$i]{'value'}) ? preg_replace('/\'\'/','"',$FIELD[$i]{'value'}) : ''; # add properties for NOT accepted uploded FILES if (!$FIELD[$i]{'value'} && isset($FIELD[$i]{'file_property'}{'size'}) && isset($FIELD[$i]{'file_property'}{'format'}) && isset($FIELD[$i]{'file_property'}{'name'})) { $FIELD[$i]{'value'} = $FIELD[$i]{'file_property'}{'name'} . ' | ' . $FIELD[$i]{'file_property'}{'size'} . ' | ' . $FIELD[$i]{'file_property'}{'format'} ; } $string .= $K . ").\t" . $FIELD[$i]{'title'} . ":\t". $FIELD[$i]{'value'} . "\n\n"; $K++; } elseif (isset($FIELD[$i]{'text'}) && $FIELD[$i]{'text'}) { $string .= "-- \t" . $FIELD[$i]{'text'} . "\n\n"; } } return $string; } #::::::::::::::::::::::::::::::::::: function send_email(&$MAIL,$email_preview=0) { $print_name = 'send_email'; # $email_preview=0 - to send email; $email_preview=1 - to show email without sending it # find emails $LIST = array('to','from','cc','bcc','test','undelivered'); $number = count($LIST); for ($i=0; $i<$number; $i++) { if (isset($MAIL{$LIST[$i]})){$MAIL{$LIST[$i]} = create_array_of_emails($MAIL{$LIST[$i]});} } # remove possible duplications of email if (!empty($MAIL{'cc'}) && !empty($MAIL{'to'})) { $MAIL{'cc'} = array_diff($MAIL{'cc'},$MAIL{'to'}); } $subject = text_vs_html($MAIL{'subject'},'text'); $message = text_vs_html($MAIL{'message'},'text'); $message = str_replace(array('','','','','
    ','
    '),'',$message); $EMAIL_CC = isset($MAIL{'cc'}) ? $MAIL{'cc'} : array(); $EMAIL_BCC = isset($MAIL{'bcc'}) ? $MAIL{'bcc'} : array(); # add appropriate Return-Path for undelivered messages $undelivered = (isset($MAIL{'undelivered'}[0])) ? $MAIL{'undelivered'}[0] : ''; $additional_parameters = ($undelivered) ? '-f' . $undelivered : ''; if (isset($MAIL{'test'}) && !empty($MAIL{'test'})){$EMAIL_BCC = array_merge($EMAIL_BCC,$MAIL{'test'});} $SENDER = (isset($MAIL{'from'})) ? $MAIL{'from'} : array(); if (isset($SENDER) && is_array($SENDER)) { $email_from = (isset($SENDER[0])) ? $SENDER[0] : ''; } else {$email_from = $SENDER;} # possibility to send "From" with description if (!$email_from && isset($MAIL{'fromtitle'}) && $MAIL{'fromtitle'}) { $email_from = $MAIL{'fromtitle'}; } $send_mail = 0; if (is_array($MAIL{'to'}) && !empty($MAIL{'to'})) { $to = implode(',',$MAIL{'to'}); $cc = (is_array($EMAIL_CC) && !empty($EMAIL_CC)) ? implode(',',$EMAIL_CC) : ''; $bcc = (is_array($EMAIL_BCC) && !empty($EMAIL_BCC)) ? implode(',',$EMAIL_BCC) : ''; $from = ($email_from) ? 'From: ' . $email_from . "\n": ''; $cc_in_header = ($cc) ? 'Cc: ' . $cc . "\n" : ''; $bcc = ($bcc) ? 'Bcc: ' . $bcc . "\n" : ''; $from = ($email_from) ? 'From: ' . $email_from . "\n": ''; $header = $from . $cc_in_header . $bcc; $message_in_body = $message; $subject_in_body = $subject; $preview_message = $message; $preview_header = $header; # attachments $TITLES = array(); if (!isset($MAIL{'attachment'})) { $MAIL{'attachment'} = array();} if (!empty($MAIL{'attachment'})) { $ARRAY = email_attachments($MAIL{'attachment'},$header,$message); $TITLES = select_property($MAIL{'attachment'},'title'); } if ($email_preview || (isset($_SERVER{'HTTP_HOST'}) && $_SERVER{'HTTP_HOST'}=='localhost')) { $message_html = clean_untrusted_string($preview_message) ; $attached_docs = (!empty($TITLES)) ? implode($TITLES,'; '): '' ; $PREVIEW = array( 'From' => $email_from, 'To' => $to, 'Cc' => $cc, 'Subject' => clean_untrusted_string($subject), 'Message' => text_vs_html($message_html,'html'), ); if ($attached_docs){$PREVIEW{'Attachments'} = $attached_docs;} if ($email_preview) { return $PREVIEW; } print '
    additional_parameters: ' . $additional_parameters . '
    '; print '
    header: '. $header . '
    '; print '
    to: ' . $PREVIEW{'To'} . '
    '; print '
    cc: ' . $PREVIEW{'Cc'} . '
    '; print '
    subject: ' . $PREVIEW{'Subject'} . '
    '; print '
    message in html:
    ' . $PREVIEW{'Message'} . '
    '; print '
    attachments'; print_variable($attached_docs); } $send_mail = 0; if (!$email_preview && $message && $to && (!isset($_SERVER{'HTTP_HOST'}) || $_SERVER{'HTTP_HOST'}!='localhost')) # NO sending emails from localhost! { $send_mail = mail($to,$subject,$message,$header,$additional_parameters); } elseif ($email_preview) { } elseif (isset($_SERVER{'HTTP_HOST'}) && $_SERVER{'HTTP_HOST'}=='localhost') { print '
    email will NOT be sent (' . $print_name . ')'; print '
    HOST (' . $print_name . ')'; print_variable($_SERVER{'HTTP_HOST'}); } } $MAIL = array(); if ($send_mail || (isset($_SERVER{'HTTP_HOST'}) && $_SERVER{'HTTP_HOST'}=='localhost')) # prepare for correspondence table { $MAIL{'Recipient'} = $to; $MAIL{'Cc'} = $cc; $MAIL{'Sender'} = $email_from; $MAIL{'Subject'} = $subject_in_body; $MAIL{'Message'} = $message_in_body; $MAIL{'DateTime'} = date('Y.m.d H:i:s'); $MAIL{'Insert_DateTime'} = date('Y.m.d H:i:s'); $MAIL{'Attachment'} = $TITLES; } return $send_mail; } #::::::::::::::::::::::::::::::::::: function string_for_database_changes($ARRAY) { $string = ''; $br = "\n"; $space = " "; $i = 1; if (is_array($ARRAY) && !empty($ARRAY)) { foreach ($ARRAY as $key => $VALUE) { $string .= $i . '). ' . str_replace('_',' ',$key) . "\n"; $string .= 'old: ' . $VALUE{'old'} . "\n"; $string .= 'new: ' . $VALUE{'new'} . "\n\n"; $i++; } } if (!$string){$string = 'No changes were made.';} return $string; } #::::::::::::::::::::::::::::::::::: function alert_box($string,$alert_class='messagebox') { # function returns some text into colored frame if ($string) { $string = "\n" . '
    ' . $string . '
    '; } return $string; } #::::::::::::::::::::::::::::::::::: function database_connection($CONNECTION) { $print_name = 'database_connection'; if (isset($_SERVER{'HTTP_HOST'}) && $_SERVER{'HTTP_HOST'}=='localhost'){$CONNECTION{'host'} = 'localhost';} if (isset($CONNECTION{'user'}) && $CONNECTION{'user'} && isset($CONNECTION{'host'}) && $CONNECTION{'host'} && isset($CONNECTION{'password'}) && $CONNECTION{'password'} && isset($CONNECTION{'database'}) && $CONNECTION{'database'}) { $connect = mysqli_connect($CONNECTION{'host'},$CONNECTION{'user'},$CONNECTION{'password'},$CONNECTION{'database'}); # check the connection if (!$connect) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; exit; } if ($connect){return $connect; } } else { print '
    NO CONNECTION ! (' . $print_name . ')'; print_variable($CONNECTION); } } #::::::::::::::::::::::::::::::::::: function full_name_for_form_field($FIELD,$FIELDS_ALL) { if (is_array($FIELD) && !empty($FIELD)) { $number = count($FIELDS_ALL); for ($i=0; $i<$number; $i++) { $ok = 1; foreach ($FIELD as $key => $value) { if ($FIELDS_ALL[$i]{$key}!=$value) { $ok = 0; break; } } if ($ok) { $NEW = add_table_and_record(array($FIELDS_ALL[$i])); $full_name = $NEW[0]{'name'}; } } } return $full_name; } #::::::::::::::::::::::::::::::::::: function change_attribute_of_specifid_field(&$FIELDS_ALL,$FIELD,$attribute,$new_attribute_value) { if (is_array($FIELD) && !empty($FIELD)) { $number = count($FIELDS_ALL); for ($i=0; $i<$number; $i++) { $ok = 1; foreach ($FIELD as $key => $value) { if ($FIELDS_ALL[$i]{$key}!=$value) { $ok = 0; break; } } if ($ok) { $FIELDS_ALL[$i]{$attribute} = $new_attribute_value; } } } } #::::::::::::::::::::::::::::::::::: function corrected_www($url) { global $PAGE; if ($url && strtolower(substr($url,0,4))!='http') { if (strtolower(substr($url,0,4))=='root') # relative link { $html_char = '/'; # - HTML replacment for '/' $url = str_replace(array('root/','ROOT/','root'. $html_char,'ROOT'. $html_char),$PAGE{'data'}{'root'},$url); } elseif (strtolower(substr($url,0,4))=='www.') # absolute link with ommited 'http' { $url = 'http://' . $url; } } return $url; } #::::::::::::::::::::::::::::::::::: function alias_array($string,$table,$edit='') { $print_name = 'alias_array'; $ALIAS = array(); if ($string && $table) { $RESULT = array(); $MATCH = array(); preg_match_all("/(_[A-Z:^_]+_)/",$string,$MATCH); $RESULT = $MATCH[1]; if (!empty($RESULT)) { $QUERY_ALIAS = array( 'tables' => $table, 'fields' => 'ID,Name,Value,Used_From_Function,Type', 'where' => 'Status="active" and Used_From_Function="" and ' . create_where('Name',$RESULT), ); if ($edit){$QUERY_ALIAS{'fields'} .= ',Edit';} $ALIAS = aliases_array($QUERY_ALIAS,$edit); } } return $ALIAS; } #::::::::::::::::::::::::::::::::::: function is_value_exists($field,$value_for_field,$table,$where_extra='') { $print_name = 'is_value_exists'; $exist = 0; if ($value_for_field) { $QUERY = array( 'tables' => $table, 'fields' => $field, 'where' => $field . '="' . $value_for_field. '"', ); if ($where_extra) { $QUERY{'where'} .= ' and (' . $where_extra . ')'; } $DATA = select_data($QUERY); if (isset($DATA[0]{$field})){$exist = 1;} } return $exist; } #::::::::::::::::::::::::::::::::::: function create_identity_value($random_number_chars,$time=1) { $print_name = 'create_identity_value'; $string = genRandomString($random_number_chars); if ($time){$string = time() . $string;} return $string; } #::::::::::::::::::::::::::::::::::: function create_directory_for_writing($dir_path) { $print_name = 'create_directory_for_writing'; $DIRS = explode('/',$dir_path); $number_last = count($DIRS) - 1; if (strstr($DIRS[$number_last],'.') && $DIRS[$number_last]!=='..') { $DIRS[$number_last] = ''; $dir_path = trim(implode($DIRS,'/')); } if ($dir_path && !is_dir($dir_path)){$mk = mkdir($dir_path);} if (isset($mk) && !$mk) { print '
    dir path! (' . $print_name . ')'; print_variable($dir_path); } } #::::::::::::::::::::::::::::::::::: function clean_data($string) { $print_name = 'clean_data'; global $PAGE; $string = trim($string); $string = str_replace("\n ","\n",$string); # remove '

    ' and '

    ' tags from beginning and end of the "string" which were added automatically by CDEditor if ((isset($PAGE{'data'}{'ckeditor'}) && $PAGE{'data'}{'ckeditor'}) && substr($string,0,3)=='

    ' && substr($string,-4,4)=='

    ') { $string = substr($string,3); $ln = strlen($string) - 4 ; $string = substr($string,0,$ln); $string = str_replace('

    ',"\n\n",$string); # HTML entities added by CKEditor if (isset($PAGE{'data'}{'html_entities'}) && !empty($PAGE{'data'}{'html_entities'})) { foreach ($PAGE{'data'}{'html_entities'} as $key => $value) { $string = str_replace($key,$value,$string); } } } if (!$string){$string = '';} return $string; } #::::::::::::::::::::::::::::::::::: function convert_date_string($date_string,$field_name='') { $print_name = 'convert_date_string'; # function checks date and changes date format # function returns : # 1) date was choosen right => string in database format "YYYY.MM.DD" or "HH:MM:SS" # 2) if there is no date choosen => string "" # 3) date was choosen incorrectly => string with letters and digit $string = ''; if (!preg_match('/[0-9]/i',$date_string)) # no date was choosen { return $string; } elseif (!strstr($date_string,'|') && !preg_match('/[a-zA-Z]/',$date_string)) # no correction needed { $string = $date_string; return $string; } else { $date_right = 1; $DAIS_IN_MONTH = array(31,29,31,30,31,30,31,31,30,31,30,31); $DATE_ARRAY = array(); $DATE = explode('|',$date_string); $number = count($DATE); for ($i=0; $i < $number; $i++) { list($key,$value) = explode(':',$DATE[$i]); $DATE_ARRAY{$key} = $value; } foreach($DATE_ARRAY as $key => $value) { if (stristr($value,$key)){$date_right = 0; break;} } if (!$date_right) { if (preg_match('/\*/',$field_name)){return $string;} # no date was choosen else {$string = $date_string; return $string;} # date was choosen incorrectly } else # all date fields were choosen { if (isset($DATE_ARRAY{'YEAR'})) # Year, month, day { $short_year = $DATE_ARRAY{'YEAR'} % 4; if ($DATE_ARRAY{'DAY'} > $DAIS_IN_MONTH[$DATE_ARRAY{'MONTH'}-1]) # there is not such day in calendar { $string = $date_string; return $string; } elseif ($DATE_ARRAY{'MONTH'} == 2 && $DATE_ARRAY{'DAY'}>28 && $short_year!=0) # there is not such day in calendar { $string = $date_string; return $string; } else { if (intval($DATE_ARRAY{'MONTH'}) < 10){$DATE_ARRAY{'MONTH'} = '0' . intval($DATE_ARRAY{'MONTH'});} if (intval($DATE_ARRAY{'DAY'}) < 10){$DATE_ARRAY{'DAY'} = '0' . intval($DATE_ARRAY{'DAY'});} $string .= $DATE_ARRAY{'YEAR'} . '.' . $DATE_ARRAY{'MONTH'} . '.' . $DATE_ARRAY{'DAY'}; } } if (isset($DATE_ARRAY{'HOUR'})) # Hour, min, sec { if ( intval($DATE_ARRAY{'HOUR'}) < 10){$DATE_ARRAY{'HOUR'} = '0' . intval($DATE_ARRAY{'HOUR'});} if ( intval($DATE_ARRAY{'MIN'}) < 10){$DATE_ARRAY{'MIN'} = '0' . intval($DATE_ARRAY{'MIN'});} if ($string){$string .= ' ';} $string .= $DATE_ARRAY{'HOUR'} . ':' . $DATE_ARRAY{'MIN'}; if (isset($DATE_ARRAY{'SEC'})) { if (intval($DATE_ARRAY{'SEC'}) < 10){$DATE_ARRAY{'SEC'} = '0' . intval($DATE_ARRAY{'SEC'});} $string .= ':' . $DATE_ARRAY{'SEC'}; } } } } return $string; } #::::::::::::::::::::::::::::::::::: function find_email($string) { # finding E-mails in text $RESULT = array(); $MATCH = array(); preg_match_all("/([^\s^:^|^\'^\"^>^\(^\)^,^;]+@[^\s^:^|^\'^\"^>^<^\(^\)^,^;]+)/i",$string,$MATCH); $RESULT = $MATCH[1]; $EMAIL = array(); $number = count($RESULT); for ($i=0; $i<$number; $i++) { $domain = strstr($RESULT[$i],'@'); if (strstr($domain,'.') && !in_array($RESULT[$i],$EMAIL)){$EMAIL[] = $RESULT[$i];} } return $EMAIL; } #::::::::::::::::::::::::::::::::::: function get_name($PERSON,$normalized=0) { $name = ''; if (isset($PERSON{'Full_Name'}) && $PERSON{'Full_Name'}) { $name = $PERSON{'Full_Name'}; if (strstr($PERSON{'Full_Name'},',')) { list($first,$second) = explode(',',trim($PERSON{'Full_Name'})); $name = $second . ' ' . $first; } } else { $PERSON{'Last_Name'} = (isset($PERSON{'Last_Name'})) ? $PERSON{'Last_Name'} : '' ; $PERSON{'First_Name'} = (isset($PERSON{'First_Name'})) ? $PERSON{'First_Name'} : '' ; $PERSON{'MI'} = (isset($PERSON{'MI'})) ? $PERSON{'MI'} : '' ; $PERSON{'M_I'} = (isset($PERSON{'M_I'})) ? $PERSON{'M_I'} : '' ; $PERSON{'Title'} = (isset($PERSON{'Title'})) ? $PERSON{'Title'} : '' ; $last_name = trim($PERSON{'Last_Name'}); $first_name = trim($PERSON{'First_Name'}); $mi = trim($PERSON{'MI'}) ? trim($PERSON{'MI'}) : trim($PERSON{'M_I'}) ; $title = trim($PERSON{'Title'}); if ($normalized) { if ($last_name) { $name = $last_name; if ($first_name){$name .= ', ' . $first_name . ' ' . $mi;} } } else { $name = $title . ' ' . $first_name . ' ' . $mi . ' ' . $last_name; } } $name = clear_string($name); return $name; } #::::::::::::::::::::::::::::::::::: function strip_single($tag,$string) { # not mine $string = preg_replace('/<'.$tag.'[^>]*>/i', '', $string); $string = preg_replace('/<\/'.$tag.'>/i', '', $string); return $string; } #::::::::::::::::::::::::::::::::::: function let_to_num($v) { # This function transforms the php.ini notation for numbers (like '2M') to an integer (2*1024*1024 in this case) $l = substr($v, -1); $ret = substr($v, 0, -1); switch(strtoupper($l)) { case 'P': $ret *= 1024; case 'T': $ret *= 1024; case 'G': $ret *= 1024; case 'M': $ret *= 1024; case 'K': $ret *= 1024; break; } return $ret; } #::::::::::::::::::::::::::::::::::: function find_by_property_array($ASS_ARRAY,$property_name,$property_value) { $print_name = 'find_by_property_array'; $ARRAY = array(); $number = count($ASS_ARRAY); for ($i=0; $i<$number; $i++) { if (isset($ASS_ARRAY[$i]{$property_name}) && $ASS_ARRAY[$i]{$property_name}==$property_value) { $ARRAY[] = $ASS_ARRAY[$i]; } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function file_ext($string) { if ($string) { $string = strrchr($string,'.'); $string = str_replace('.','',$string); if (!$string){$string = 'file';} } return $string; } #::::::::::::::::::::::::::::::::::: function string_to_url($string,$type='-') { $print_name = 'string_to_url'; $double = $type . $type; $string = str_replace(' ',$type,$string); while (strstr($string,$double)){$string = str_replace($double,$type,$string);} $string = preg_replace("/[^0-9a-zA-Z-_]/",'',$string); $string = strtolower($string); return $string; } #::::::::::::::::::::::::::::::::::: function file_name($string) { if ($string) { $position = strrpos($string,'.'); if ($position) { $string = substr($string,0,$position); } } return $string; } #::::::::::::::::::::::::::::::::::: function filetype_unix($filepath,$full=0) { $print_name = 'filetype_unix'; $string = ''; $ARRAY = array( 'pdf' => array('PDF'), 'png' => array('PNG'), ); $string = exec('file ' . $filepath); $string = trim(str_replace($filepath .':','',$string)); if (!$full) { if ($string && is_array($ARRAY) && !empty($ARRAY)) { foreach ($ARRAY as $key => $VALUE) { $number = count($VALUE); for ($i=0; $i<$number; $i++) { if (preg_match('/[\s\/;:-]*' . $VALUE[$i]. '[\s\/;:-]*/',$string)) { $string = $VALUE[$i]; break; } } } } } return $string; } #::::::::::::::::::::::::::::::::::: function check_security_field($security_field) { global $PARAMS; $ststus = 'ok'; if ($security_field) { if ($_SESSION{$security_field}) # not empty form { if (strtolower($_SESSION{$security_field})!=strtolower($PARAMS{$security_field})) # wrong security code { $status = 'wrong'; } else { $status = 'ok'; $_SESSION{'security_ok'} = 1; } } else {$status = 'add';} # empty form (to 'add' security field) } return $status; } #::::::::::::::::::::::::::::::::::: function fields_for_security_image($security_field,$link_to_image='',$size='') { global $PAGE; $EXTRA = array(); if ($security_field) { # $link_to_imag - link to file that generates the dynamic security image if (!$link_to_image){$link_to_image = $PAGE{'data'}{'root'} . 'kit/form/security-image.php' ;} if (!$size){$size = 40;} $EXTRA = array( array( 'text' => '


    ', 'security' => 1, 'step' => 1, ), array( 'text' => 'Security Code: ', 'security' => 1, 'step' => 1, ), array( 'title' => str_replace('_',' ',$security_field), 'name' => $security_field, 'type' => 'text', 'not_null' => 1, 'size' => $size, 'comments' => 'Please, type the security code (see above)', 'security' => 1, 'step' => 1, ), ); } return $EXTRA; } #::::::::::::::::::::::::::::::::::: function extra_step_field_name($ARRAY,$FIELDS) { $string = ''; if (is_array($ARRAY) && !empty($ARRAY)) { $KEYS = array_keys($ARRAY); $UPLOAD = find_by_property_array($FIELDS,'type','File'); if (!empty($UPLOAD)) { $NAMES = select_property($UPLOAD,'name'); if (!empty($NAMES) && !empty($KEYS)) { $NEW = array_values(array_intersect($NAMES,$KEYS)); $string = $NEW[0]; } } } return $string; } #::::::::::::::::::::::::::::::::::: function change_field_length($FIELDS) { # if there is a database to put the data then change text field length arroding to the lenth of the fields in the database global $CONNECTION; $DATA = array(); $number = count($FIELDS); for ($i=0; $i<$number; $i++) { $table = ($FIELDS[$i]{'table'}) ? $FIELDS[$i]{'table'} : $CONNECTION{'table'}; if ($table) { if (!isset($DATA{$table})){$DATA{$table} = array();} $DATA{$table}[] = $FIELDS[$i]; } } if (!empty($DATA)) { $connection_database = database_connection($CONNECTION,$connection_error); if ($connection_error){print "
    ".$connection_error."
    ";} else { foreach ($DATA as $key => $VALUE) { $VALUE = field_length_in_table($database,$table,$VALUE); } } } return $FIELDS; } #::::::::::::::::::::::::::::::::::: function extra_fields_for_step($ARRAY,$current_step,$number_steps,&$submit_button,$verify_step) { $print_name = 'extra_fields_for_step'; global $FORM; $EXTRA = array(); $NEW = array(); # verify field $verify = (isset($FORM{'verify_steps'})) ? $FORM{'verify_steps'} : ''; $verify_at_end = (isset($FORM{'verify_at_end'})) ? $FORM{'verify_at_end'} : 0; $verify_step = ($current_step<=$number_steps) ? $current_step : $verify_step ; $NEW = verification_field($verify,$verify_step); # form button if ($current_step<$number_steps || !empty($NEW) || $verify_at_end) { $submit_button = (isset($FORM{'continue_button'}) && $FORM{'continue_button'}) ? $FORM{'continue_button'} : 'Continue'; } else { $submit_button = $FORM{'submit_button'}; } $step = 'step'; if ($current_step!=1) { $EXTRA[] = array( 'title' => $step, 'name' => $step, 'type' => 'Hidden', 'value' => $current_step, ); } if (isset($FORM{'check'}{'value'}) && $FORM{'check'}{'value'}) # to check lost session { $check = 'check'; # to check lost session $EXTRA[] = array( 'title' => $check, 'name' => $check, 'type' => 'Hidden', 'value' => $FORM{'check'}{'value'}, ); $step_time = 'step_start'; # to check time duration for lost session $EXTRA[] = array( 'title' => $step_time, 'name' => $step_time, 'type' => 'Hidden', 'value' => time(), ); } # form fields for current step $EXTRA = array_merge($EXTRA,$NEW); return $EXTRA; } #::::::::::::::::::::::::::::::::::: function empty_security_field($security_field,$FIELDS) { # set empty value for security field $number = count($FIELDS{'fields'}); for ($i=0; $i<$number; $i++) { if (isset($FIELDS{'fields'}[$i]{'name'}) && $FIELDS{'fields'}[$i]{'name'}==$security_field) { $FIELDS{'fields'}[$i]{'value'} = ''; break; } } return $FIELDS; } #::::::::::::::::::::::::::::::::::: function upload_required($ARRAY) { $string = ''; $NEW = find_by_property_array($ARRAY,'type','File'); if (!empty($NEW)){$string = 'enctype="multipart/form-data"';} return $string; } #::::::::::::::::::::::::::::::::::: function form($FIELD_ATTRIBUTES,$database_table,$replace,$SIZE_DEFAULT=array(),$table_cols=2,$align='right') { $print_name = 'form'; global $PAGE,$PARAMS; $space = ' '; $br = '
    '; $hr = '
    '; $HIDDEN = array(); # array for hidden fields # create a form as a table without {
    ,
    tags and submit button} # $table_cols - number cols in form table: 1; 2 # $align - align attribute for left col (name of the element): 'right', 'left' if (!isset($align) || !$align){$align = 'right';} $width_col_1 = ''; if ($table_cols==2) { if (isset($SIZE_DEFAULT{'width_left_col'}) && $SIZE_DEFAULT{'width_left_col'}) { $width_col_1 = ' width="' . $SIZE_DEFAULT{'width_left_col'} . '"'; } else {$width_col_1 = ' width="50%"';} } $table = ''; $number = count($FIELD_ATTRIBUTES); $number_visible = 0; $number_required = 0; $step_max = 1; for ($i=0; $i<$number; $i++) { if (isset($FIELD_ATTRIBUTES[$i]{'type'}) && !stristr($FIELD_ATTRIBUTES[$i]{'type'},'hidden')){$number_visible++;} if (isset($FIELD_ATTRIBUTES[$i]{'not_null'}) && $FIELD_ATTRIBUTES[$i]{'not_null'}){$number_required++;} if (isset($FIELD_ATTRIBUTES[$i]{'step'}) && $FIELD_ATTRIBUTES[$i]{'step'}>$step_max){$step_max = $FIELD_ATTRIBUTES[$i]{'step'};} if (!isset($FIELD_ATTRIBUTES[$i]{'comments_align'}) || !$FIELD_ATTRIBUTES[$i]{'comments_align'}){$FIELD_ATTRIBUTES[$i]{'comments_align'} = 'right';} } $alert_for_required = 1; # if all fields are required than do not put alert on this fields for ($i=0; $i<$number; $i++) { if (!isset($FIELD_ATTRIBUTES[$i]{'joined'}) || !$FIELD_ATTRIBUTES[$i]{'joined'}) # skip joined fields (which will be joined to another field) { $line = ''; $FIELD_ATTRIBUTES[$i]{'value'} = (isset($FIELD_ATTRIBUTES[$i]{'value'})) ? $FIELD_ATTRIBUTES[$i]{'value'} : '' ; if (!isset($FIELD_ATTRIBUTES[$i]{'text'}) || !$FIELD_ATTRIBUTES[$i]{'text'}) # for form elements { $SIZE = $SIZE_DEFAULT; # set special size for form element ('cols', 'rows') if there is if (isset($FIELD_ATTRIBUTES[$i]{'size'}{'cols'}) && $FIELD_ATTRIBUTES[$i]{'size'}{'cols'}) {$SIZE{'cols'} = $FIELD_ATTRIBUTES[$i]{'size'}{'cols'};} if (isset($FIELD_ATTRIBUTES[$i]{'size'}{'rows'}) && $FIELD_ATTRIBUTES[$i]{'size'}{'rows'}) {$SIZE{'rows'} = $FIELD_ATTRIBUTES[$i]{'size'}{'rows'};} # options and value_options arrays if (isset($FIELD_ATTRIBUTES[$i]{'options'}) || stristr($FIELD_ATTRIBUTES[$i]{'type'},'Radioset') || stristr($FIELD_ATTRIBUTES[$i]{'type'},'Checkboxset') || stristr($FIELD_ATTRIBUTES[$i]{'type'},'Select')) { $SIZE{'table'} = (isset($SIZE{'table'})) ? $SIZE{'table'} : array() ; if (!isset($FIELD_ATTRIBUTES[$i]{'options'}) || !is_array($FIELD_ATTRIBUTES[$i]{'options'})) { $FIELD_ATTRIBUTES[$i]{'options'} = array(); } if (!isset($FIELD_ATTRIBUTES[$i]{'value_options'})) { $FIELD_ATTRIBUTES[$i]{'value_options'} = $FIELD_ATTRIBUTES[$i]{'options'}; } # add empty element if required if (!isset($FIELD_ATTRIBUTES[$i]{'empty'})){$FIELD_ATTRIBUTES[$i]{'empty'} = 0;} if ($FIELD_ATTRIBUTES[$i]{'empty'} && !empty($FIELD_ATTRIBUTES[$i]{'options'})) { $FIELD_ATTRIBUTES[$i]{'options'} = array_merge(array(''),$FIELD_ATTRIBUTES[$i]{'options'}); $FIELD_ATTRIBUTES[$i]{'value_options'} = array_merge(array(''),$FIELD_ATTRIBUTES[$i]{'value_options'}); } } # prompt for required fields $text_alert = (isset($FIELD_ATTRIBUTES[$i]{'not_null'}) && $FIELD_ATTRIBUTES[$i]{'not_null'} && $alert_for_required) ? $text_alert = 'alert' : '' ; # alert for WRONG or EMPTY fields $td_alert = (!empty($_POST) && isset($FIELD_ATTRIBUTES[$i]{'alert'}) && $FIELD_ATTRIBUTES[$i]{'alert'}) ? 'class="alert"' : '' ; $field_comments = ''; $field_name = ''; if (!stristr($FIELD_ATTRIBUTES[$i]{'type'},'Hidden')) { if (isset($FIELD_ATTRIBUTES[$i]{'title'}) && $FIELD_ATTRIBUTES[$i]{'title'}) { $field_name = $FIELD_ATTRIBUTES[$i]{'title'}; if (isset($FIELD_ATTRIBUTES[$i]{'not_null'}) && $FIELD_ATTRIBUTES[$i]{'not_null'} && $alert_for_required && !stristr($field_name,'(required)')){$field_name .= ' (required)';} } else { $field_name = $FIELD_ATTRIBUTES[$i]{'name'}; $field_name = str_replace('_',' ',$field_name); $field_name = ucfirst($field_name); } if (strtolower($FIELD_ATTRIBUTES[$i]{'type'})=='file') # comments for upload file { $ITEM = array(); if (isset($FIELD_ATTRIBUTES[$i]{'comments'}) && $FIELD_ATTRIBUTES[$i]{'comments'}){$ITEM[] = $FIELD_ATTRIBUTES[$i]{'comments'} ;} # file size $max_upload_size = min(let_to_num(ini_get('post_max_size')), let_to_num(ini_get('upload_max_filesize'))); $mb = 1024*1024; $max_upload_size = intval($max_upload_size/$mb); if (!isset($FIELD_ATTRIBUTES[$i]{'file_size'}) || !$FIELD_ATTRIBUTES[$i]{'file_size'} || $FIELD_ATTRIBUTES[$i]{'file_size'}>$max_upload_size){$FIELD_ATTRIBUTES[$i]{'file_size'} = $max_upload_size; } if (isset($FIELD_ATTRIBUTES[$i]{'file_size'}) && $FIELD_ATTRIBUTES[$i]{'file_size'}){$ITEM[] = 'up to: ' .$FIELD_ATTRIBUTES[$i]{'file_size'}. 'MB' ;} if (isset($FIELD_ATTRIBUTES[$i]{'file_format'}) && is_array($FIELD_ATTRIBUTES[$i]{'file_format'}) && !empty($FIELD_ATTRIBUTES[$i]{'file_format'})){$ITEM[] = 'accepted format: ' . implode($FIELD_ATTRIBUTES[$i]{'file_format'},', ') ;} if (!empty($ITEM)){$FIELD_ATTRIBUTES[$i]{'comments'} = implode($ITEM, $br);} } if (isset($FIELD_ATTRIBUTES[$i]{'comments'}) && $FIELD_ATTRIBUTES[$i]{'comments'}) { $field_comments .= $FIELD_ATTRIBUTES[$i]{'comments'} ; } } # remove HTML break line from actual form field if ((!isset($FIELD_ATTRIBUTES[$i]{'type'}) || !stristr($FIELD_ATTRIBUTES[$i]{'type'},'info')) && (!isset($FIELD_ATTRIBUTES[$i]{'text'}) || !$FIELD_ATTRIBUTES[$i]{'text'}) && (isset($FIELD_ATTRIBUTES[$i]{'value'}) && stristr($FIELD_ATTRIBUTES[$i]{'value'},'','
    '),"\n",$FIELD_ATTRIBUTES[$i]{'value'}); } $field_value = (isset($FIELD_ATTRIBUTES[$i]{'value'}) && $FIELD_ATTRIBUTES[$i]{'value'}) ? $FIELD_ATTRIBUTES[$i]{'value'} : '' ; $element_name = (isset($database_table) && $database_table) ? $database_table . ':' : '' ; $element_name .= $FIELD_ATTRIBUTES[$i]{'name'}; # INFO if (strtolower($FIELD_ATTRIBUTES[$i]{'type'})=='info') { $field_value = text_vs_html($FIELD_ATTRIBUTES[$i]{'value'},'html'); } elseif (strtolower($FIELD_ATTRIBUTES[$i]{'type'})=='button') { $field_value = ''; $field = new form_element_string($element_name,$field_name,'Hidden',$FIELD_ATTRIBUTES[$i]{'value'}); $field_value .= $field->output; } # TEXT AREA elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Textarea')) { $FIELD_ATTRIBUTES[$i]{'value'} = (isset($FIELD_ATTRIBUTES[$i]{'value'})) ? $FIELD_ATTRIBUTES[$i]{'value'} : '' ; # add space before "\n" to see a new line - to help formating if ($FIELD_ATTRIBUTES[$i]{'value'}) { $FIELD_ATTRIBUTES[$i]{'value'} = str_replace(array("\n"),array("\n "),$FIELD_ATTRIBUTES[$i]{'value'}); $FIELD_ATTRIBUTES[$i]{'value'} = clean_empty_space($FIELD_ATTRIBUTES[$i]{'value'}); } if (!isset($FIELD_ATTRIBUTES[$i]{'editor'})) # CKEditor { $FIELD_ATTRIBUTES[$i]{'editor'} = 0; } $field = new form_element_textarea($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'value'},$SIZE{'cols'},$SIZE{'rows'},$FIELD_ATTRIBUTES[$i]{'editor'}); $field_value = $field->output; } # UPLOAD FILE elseif (strtolower($FIELD_ATTRIBUTES[$i]{'type'})=='file') { if (!isset($FIELD_ATTRIBUTES[$i]{'file_name'})){$FIELD_ATTRIBUTES[$i]{'file_name'} = '' ;} if (!isset($FIELD_ATTRIBUTES[$i]{'file_format'})){$FIELD_ATTRIBUTES[$i]{'file_format'} = array() ;} # to update/delete previous value $field_value = ''; if (isset($FIELD_ATTRIBUTES[$i]{'value'}) && $FIELD_ATTRIBUTES[$i]{'value'}) { $FILE_ITEM = explode('|',$FIELD_ATTRIBUTES[$i]{'value'}); $file_attached = (isset($FILE_ITEM[1]) && $FILE_ITEM[1]) ? $FILE_ITEM[1] : file_name_and_ext($FILE_ITEM[0]); $field_value = 'attached: ' . site_www($file_attached,$PAGE{'data'}{'root'} . $FILE_ITEM[0],1) . $br ; } if ($field_value) { $FIELD_ATTRIBUTES[$i]{'options'} = array($field_value,'change'); $FIELD_ATTRIBUTES[$i]{'value_options'} = array($FIELD_ATTRIBUTES[$i]{'value'},'to_reupload'); if (!isset($FIELD_ATTRIBUTES[$i]{'not_null'}) || !$FIELD_ATTRIBUTES[$i]{'not_null'}) { $FIELD_ATTRIBUTES[$i]{'options'}[] = 'delete'; $FIELD_ATTRIBUTES[$i]{'value_options'}[] = ''; } if (!isset($SIZE{'table'})) {$SIZE{'table'} = array() ;} $field = new form_element_radioset($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'options'},$FIELD_ATTRIBUTES[$i]{'value'},$FIELD_ATTRIBUTES[$i]{'value_options'},$SIZE{'table'}); } else { $field = new form_element_file($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'file_name'},$FIELD_ATTRIBUTES[$i]{'file_format'}); } $field_value = $field->output; } # HIDDEN elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Hidden')) { $FIELD_ATTRIBUTES[$i]{'id'} = (isset($FIELD_ATTRIBUTES[$i]{'id'})) ? $FIELD_ATTRIBUTES[$i]{'id'} : ''; $field = new form_element_string($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'type'},$FIELD_ATTRIBUTES[$i]{'value'},'','',$FIELD_ATTRIBUTES[$i]{'id'}); $field_value = $field->output; $HIDDEN[] = $field_value; continue; # do not put hidden fields into the table, put hidden fields after the table } # DROP LIST elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Select')) { $SIZE{'select_row'} = (isset($SIZE{'select_row'})) ? $SIZE{'select_row'} : ''; $field = new form_element_select($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'type'},$FIELD_ATTRIBUTES[$i]{'options'},$FIELD_ATTRIBUTES[$i]{'value'},$FIELD_ATTRIBUTES[$i]{'value_options'},$SIZE{'select_row'}); $field_value=$field->output; } # RADIO SET with OTHER option elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Radioset')) { # style - 'ver' or 'hor' - to show radioboxes $SIZE{'table'}{'type'} = (isset($FIELD_ATTRIBUTES[$i]{'style'}) && $FIELD_ATTRIBUTES[$i]{'style'}) ? $FIELD_ATTRIBUTES[$i]{'style'} : 'ver'; $OTHER_OPTION = array(); if (isset($FIELD_ATTRIBUTES[$i]{'other'}) && $FIELD_ATTRIBUTES[$i]{'other'}) { $other_name = add_table_and_record_to_field(array('name'=>$FIELD_ATTRIBUTES[$i]{'other'},'table'=>$FIELD_ATTRIBUTES[$i]{'table'})); $OTHER_OPTION = find_by_property_array($FIELD_ATTRIBUTES,'name',$other_name); if (isset($OTHER_OPTION[0])){$OTHER_OPTION = $OTHER_OPTION[0];} } $field = new form_element_radioset($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'options'},$FIELD_ATTRIBUTES[$i]{'value'},$FIELD_ATTRIBUTES[$i]{'value_options'},$SIZE{'table'},$OTHER_OPTION); $field_value=$field->output; } # CHECKBOX SET elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Checkboxset')) { # style - 'ver' or 'hor' - to show checkboxset $SIZE{'table'}{'type'} = (isset($FIELD_ATTRIBUTES[$i]{'style'}) && $FIELD_ATTRIBUTES[$i]{'style'}) ? $FIELD_ATTRIBUTES[$i]{'style'} : 'ver'; $field = new form_element_checkboxset($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'options'},$FIELD_ATTRIBUTES[$i]{'value'},$FIELD_ATTRIBUTES[$i]{'value_options'},$SIZE{'table'}); $field_value=$field->output; } # DATE and TIME elseif (stristr($FIELD_ATTRIBUTES[$i]{'type'},'Date') || stristr($FIELD_ATTRIBUTES[$i]{'type'},'Time')) { if (!stristr($FIELD_ATTRIBUTES[$i]{'type'},'Date')) # TIME only { if (!isset($SIZE['min_step'])){$SIZE['min_step'] = 1;} $field = new form_element_time($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'type'},$SIZE{'min_step'},$FIELD_ATTRIBUTES[$i]{'value'}); } else { if (!isset($SIZE{'dates'}{$FIELD_ATTRIBUTES[$i]{'name'}})){$SIZE{'dates'}{$FIELD_ATTRIBUTES[$i]{'name'}} = array();} if (!isset($SIZE['year_start'])){$SIZE['year_start'] = date('Y') -1;} if (!isset($SIZE['year_end'])){$SIZE['year_end'] = date('Y') + 1;} if (!isset($SIZE['min_step'])){$SIZE['min_step'] = 5;} $field = new form_element_datetime($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'type'},$SIZE['year_start'],$SIZE['year_end'],$SIZE['min_step'],$FIELD_ATTRIBUTES[$i]{'value'},$SIZE{'dates'}{$FIELD_ATTRIBUTES[$i]{'name'}}); } $field_value = $field->output; } else # TEXT { $FIELD_ATTRIBUTES[$i]{'value'} = (isset($FIELD_ATTRIBUTES[$i]{'value'})) ? $FIELD_ATTRIBUTES[$i]{'value'} : '' ; $FIELD_ATTRIBUTES[$i]{'id'} = (isset($FIELD_ATTRIBUTES[$i]{'id'})) ? $FIELD_ATTRIBUTES[$i]{'id'} : '' ; $FIELD_ATTRIBUTES[$i]{'length'} = (isset($FIELD_ATTRIBUTES[$i]{'length'})) ? $FIELD_ATTRIBUTES[$i]{'length'} : '' ; $field = new form_element_string($element_name,$field_name,$FIELD_ATTRIBUTES[$i]{'type'},$FIELD_ATTRIBUTES[$i]{'value'},$SIZE{'cols'},$FIELD_ATTRIBUTES[$i]{'length'},$FIELD_ATTRIBUTES[$i]{'id'}); $field_value = $field->output; } if (!stristr($FIELD_ATTRIBUTES[$i]{'type'},'Hidden')) { if ($text_alert){$text_alert = 'class="' . $text_alert . '"' ;} if ($field_comments){$field_comments = '' . $field_comments . '
    ';} $field_name = '' . $field_name . ''; if ($FIELD_ATTRIBUTES[$i]{'comments_align'}=='left') { $field_name .= $br . $field_comments; } else { if (isset($FIELD_ATTRIBUTES[$i]{'type'}) && $field_comments && ((strtolower($FIELD_ATTRIBUTES[$i]{'type'})=='file' && !$FIELD_ATTRIBUTES[$i]{'value'}) || stristr($FIELD_ATTRIBUTES[$i]{'type'},'date') || stristr($FIELD_ATTRIBUTES[$i]{'type'},'time') || stristr($FIELD_ATTRIBUTES[$i]{'type'},'textarea'))) { $field_comments .= $br ; } $field_value = $field_comments . $field_value; } } if ($table_cols == 1) { if ($field_name) { $field_name = '' . $field_name . '' ; } $field_value = '' . $field_value . ''; } elseif (isset($FIELD_ATTRIBUTES[$i]{'block'}) && $FIELD_ATTRIBUTES[$i]{'block'} == 1) { if ($field_name) { $field_name = '' . $field_name . ''; } $field_value = '' . $field_value . ''; } else { if ($field_name) { $field_name = '' . $field_name . '' ; $field_value = '' . $field_value . ''; } else {$field_value = '' . $field_value . '';} } $line = $field_name . $field_value; } else # for some TEXT (NOT form elements) inside the form { $class = ''; $class_title = ''; $class_comments = ''; if (isset($FIELD_ATTRIBUTES[$i]{'class'}) && $FIELD_ATTRIBUTES[$i]{'class'}) { $class = 'class="' . $FIELD_ATTRIBUTES[$i]{'class'} . '"'; $class_title = 'class="' . $FIELD_ATTRIBUTES[$i]{'class'} . '-title"'; $class_comments = 'class="' . $FIELD_ATTRIBUTES[$i]{'class'} . '-comments"'; } $line = '' . $FIELD_ATTRIBUTES[$i]{'text'} . ''; if (isset($FIELD_ATTRIBUTES[$i]{'comments'}) && $FIELD_ATTRIBUTES[$i]{'comments'}) { $line .= '' . $FIELD_ATTRIBUTES[$i]{'comments'} . ''; } $line = '' . $line . ''; } $table .= $line ; } } $hidden_fields = ''; if (!empty($HIDDEN)) { $hidden_fields = implode($HIDDEN,''); } $form = '' . $table . '
    ' . $hidden_fields ; return $form; } #::::::::::::::::::::::::::::::::::: function selected_field_value(&$FIELD,$separator=';') { $print_name = 'selected_field_value'; $NEW = array(); if (isset($FIELD{'value_options'}) && $FIELD{'value_options'} && $FIELD{'options'} && isset($FIELD{'options'})) { $FIELD{'value'} = (isset($FIELD{'value'})) ? $FIELD{'value'} : '' ; $NEW = (isset($FIELD{'value'}) && strstr($FIELD{'value'},$separator)) ? explode($separator,$FIELD{'value'}) : array($FIELD{'value'}); $number = count($NEW); $number_options = count($FIELD{'value_options'}); if ($number_options) { for ($i=0; $i<$number; $i++) { for ($j=0; $j<$number_options; $j++) { if ($FIELD{'value_options'}[$j]==$NEW[$i]) { $NEW[$i] = $FIELD{'options'}[$j]; break; } } } } } if (!empty($NEW)) {$FIELD{'value'} = implode($NEW,$separator);} } #::::::::::::::::::::::::::::::::::: function show_list($ARRAY,$class_ul='',$class_li='') { $print_name = 'show_list'; $string = ''; $number = count($ARRAY); for ($i=0; $i<$number; $i++) { $class = ($class_li) ? 'class="' . $class_li . '"' : ''; $string .= '
  • ' . $ARRAY[$i] . '
  • '; } if ($string) { $class = ($class_ul) ? 'class="' . $class_ul . '"' : '' ; $string = '
      ' . $string . '
    '; } return $string; } #::::::::::::::::::::::::::::::::::: function event_dates($DATES,$brief=0) { $print_name = 'event_dates'; $dates = ''; $month = ($brief) ? 'M': 'F'; if (!is_array($DATES)) { if ($DATES) { $dates = date($month . ' j, Y',convert_database_date($DATES)); } } else { if (isset($DATES{'start'}) && $DATES{'start'}) { if (!isset($DATES{'finish'}) || !$DATES{'finish'}){$DATES{'finish'} = $DATES{'start'};} $time_start = convert_database_date($DATES{'start'}); $time_finish = convert_database_date($DATES{'finish'}); if ($time_start == $time_finish) { $dates = date($month . ' j, Y',$time_start); } elseif (date('Y',$time_start) == date('Y',$time_finish) && date($month,$time_start)==date($month,$time_finish)) { $dates = date($month .' j',$time_start) .' - ' . date('j, Y',$time_finish); } elseif (date('Y',$time_start) == date('Y',$time_finish)) { $dates = date($month .' j',$time_start) . ' - ' . date($month . ' j, Y',$time_finish); } else { $dates = date($month . ' j, Y',$time_start) . ' - ' . date($month . ' j, Y',$time_finish); } } } return $dates; } #::::::::::::::::::::::::::::::::::: function file_name_and_ext($string) { if ($string) { if (strstr($string,'/')) { $string = strrchr($string,'/'); $string = str_replace('/','',$string); } if (!$string){$string = 'File';} } return $string; } #::::::::::::::::::::::::::::::::::: function sort_by_colomn(&$ARRAY,$sort_colomn,$sort_order='',$html_remove=0,$DATE_FORMAT=array()) { $number = count($ARRAY); $COLUMN = array(); if ($number) { if (in_array($sort_colomn,array_keys($ARRAY[0]))) { for ($i=0; $i<$number; $i++) { $COLUMN[$i] = (isset($ARRAY[$i]{$sort_colomn})) ? strtolower($ARRAY[$i]{$sort_colomn}) : ''; } } # remove html tags from values of the sorting colomn if ($html_remove) { for ($i=0; $i<$number; $i++) { $COLUMN[$i] = trim(preg_replace("/<[^<^>]+>/"," ",$COLUMN[$i])); } } # sort by DATE if (strstr($sort_colomn,'Date')) { for ($i=0; $i<$number; $i++) { $COLUMN[$i] = convert_date_to_sort($COLUMN[$i]); } } $not_null = 0; for ($i=0; $i<$number; $i++) { if($COLUMN[$i]){$not_null = 1; break;} } if ($not_null) { if (stristr($sort_order,'desc')){arsort($COLUMN);} else {asort($COLUMN);} } $KEYS = array_keys($COLUMN); $number = count($KEYS); $ARRAY_NEW = array(); for ($i=0; $i<$number; $i++) { $ARRAY_NEW[$i] = $ARRAY[$KEYS[$i]]; } $ARRAY = $ARRAY_NEW; } } #::::::::::::::::::::::::::::::::::: function data_from_database_for_uploaded_names($FIELDS,$UPLOAD_NAMING) { $print_name = 'data_from_database_for_uploaded_names'; $ARRAY = array(); # ID value from GET $IDENTITY = identity_record_from_url(); $id = (isset($IDENTITY{'value'})) ? $IDENTITY{'value'} : 0 ; $param = (isset($IDENTITY{'param'})) ? $IDENTITY{'param'} : '' ; $OWN = (isset($UPLOAD_NAMING{'own'})) ? $UPLOAD_NAMING{'own'} : array(); $NEW = array(); # take data from database (if needed to create name for uploaded files) if ($id && $param && !empty($UPLOAD_NAMING)) { $RECORD = record_essential($IDENTITY,$OWN); $ITEMS = select_property($FIELDS,'fields_naming'); $number = count($ITEMS); for ($i=0; $i<$number; $i++) { $ITEM = (isset($ITEMS[$i]{'tables'})) ? $ITEMS[$i]{'tables'} : array() ; if (!empty($ITEM)) { foreach ($ITEM as $key => $VALUE) { if (is_array($VALUE) && !empty($VALUE)) { if (!isset($NEW{$key})){$NEW{$key} = array();} $NEW{$key} = array_values(array_unique(array_merge($NEW{$key},$VALUE))); } } } } if (!empty($NEW)) { foreach ($UPLOAD_NAMING as $key => $VALUE) { if (isset($VALUE{'table'}) && $VALUE{'table'} && isset($NEW{$VALUE{'table'}}) && !empty($NEW{$VALUE{'table'}})) { $where = '' ; if ($key=='own') # record itself { if (isset($RECORD{'identity_field'}{'value'}) && $RECORD{'identity_field'}{'value'} && isset($VALUE{'identity'}{'identity_field'}) && $VALUE{'identity'}{'identity_field'}) { $where = $VALUE{'identity'}{'identity_field'} . '="' . $RECORD{'identity_field'}{'value'} . '"' ; } } elseif ($key=='host') # HOST record { if (isset($RECORD{'host_field'}{'value'}) && $RECORD{'host_field'}{'value'} && isset($VALUE{'identity'}{'id_field'}) && $VALUE{'identity'}{'id_field'}) { $where = $VALUE{'identity'}{'id_field'} . '="' . $RECORD{'host_field'}{'value'} . '"' ; } } elseif ($key=='related') # RELATED record { if (isset($RECORD{'foreing_field'}{'value'}) && $RECORD{'foreing_field'}{'value'} && isset($VALUE{'identity'}{'host_field'}) && $VALUE{'identity'}{'host_field'}) { $where = $VALUE{'identity'}{'host_field'} . '="' . $RECORD{'host_field'}{'value'} . '"' ; } } if ($where) { $QUERY = array( 'tables' => $VALUE{'table'}, 'fields' => implode($NEW{$VALUE{'table'}},','), 'where' => $where, ); $DATA = select_data($QUERY); if (isset($DATA[0])){$ARRAY{$VALUE{'table'}} = $DATA[0] ;} } } } } } # for NEW record find the last existing ID if (!empty($OWN) && (!$id || $param=='key')) { $own_field = clean_field_name($OWN{'identity'}{'id_field'}); $next_ID = next_ID_will_be($OWN{'table'},$own_field); if ($next_ID && (!isset($ARRAY{$OWN{'table'}}{$own_field}) || !$ARRAY{$OWN{'table'}}{$own_field})) { $ARRAY{$OWN{'table'}}{$own_field} = $next_ID; } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function creating_uploaded_file_name($string,$NAMING,$DATA_SUBMITTED,$DATA_FROM_DATABASE=array(),$separator='-') { $ALIAS = (isset($NAMING{'alias'})) ? $NAMING{'alias'} : array() ; $TABLES = (isset($NAMING{'tables'})) ? $NAMING{'tables'} : array() ; if ($string && !empty($TABLES)) { # submitted data $SUBMITTED = array(); if (!empty($DATA_SUBMITTED)) { $number = count($DATA_SUBMITTED); for ($i=0; $i<$number; $i++) { $table = (isset($DATA_SUBMITTED[$i]{'table'})) ? $DATA_SUBMITTED[$i]{'table'} : '' ; if ($table) { if (!isset($SUBMITTED{$table})){$SUBMITTED{$table} = array();} $field_name = substr($DATA_SUBMITTED[$i]{'name'},0,strpos($DATA_SUBMITTED[$i]{'name'},'__')); $SUBMITTED{$table}{$field_name} = (isset($DATA_SUBMITTED[$i]{'value'}) && (trim($DATA_SUBMITTED[$i]{'value'}))) ? $DATA_SUBMITTED[$i]{'value'} : ''; } } } $NEW = explode($separator,$string); $number = count($NEW); $ELEMENTS = array(); $ARRAY = $NEW; # replace field name with data foreach ($TABLES as $key => $VALUE) { for ($i=0; $i<$number; $i++) { $field_name = (isset($ALIAS{$NEW[$i]}) && $ALIAS{$NEW[$i]}) ? $ALIAS{$NEW[$i]} : $NEW[$i]; if (in_array($field_name,$VALUE) && !in_array($NEW[$i],$ELEMENTS)) { if (isset($SUBMITTED{$key}) && is_array($SUBMITTED{$key}) && in_array($field_name,array_keys($SUBMITTED{$key}))) # name from submitted data { $ELEMENTS[] = $NEW[$i]; $ARRAY[$i] = $SUBMITTED{$key}{$field_name}; } elseif (isset($DATA_FROM_DATABASE{$key}) && is_array($DATA_FROM_DATABASE{$key}) && in_array($field_name,array_keys($DATA_FROM_DATABASE{$key}))) # name from database data { $ELEMENTS[] = $NEW[$i]; $ARRAY[$i] = (isset($DATA_FROM_DATABASE{$key}{$field_name}) && trim($DATA_FROM_DATABASE{$key}{$field_name})) ? $DATA_FROM_DATABASE{$key}{$field_name} : ''; } } } } # take only not empty values $ITEM = array(); $number = count($ARRAY); for ($i=0; $i<$number; $i++) { if (trim($ARRAY[$i])){$ITEM[] = trim($ARRAY[$i]);} } if (!empty($ITEM)){$string = implode($ITEM,$separator);} } if (!$string){$string = 'file';} return $string; } #::::::::::::::::::::::::::::::::::: function write_into_directory($file_source,$file,$version_separator,$overwrite=0) { $ok = 0; if (is_file($file_source) && $file) { $NON = array(); if (!$overwrite) # check for file with the same name { if(is_file($file)) { # properties of a file to be written $ITEM = file_directory_name_ext_version($file,$version_separator); # list files in the directory $FILE = array(); $LIST = array($ITEM{'directory'}); $DIRECTORY = array(); directory_list($LIST,$DIRECTORY,$FILE); $number = count($FILE); $VERSIONS = array(); for ($i=0; $i<$number; $i++) { $NEW = file_directory_name_ext_version($FILE[$i],$version_separator); if ($NEW{'ext'}==$ITEM{'ext'} && $NEW{'name'}==$ITEM{'name'}) { $VERSIONS[] = $NEW{'version'}; } } $ITEM{'version'} = max($VERSIONS) + 1; if ($ITEM{'directory'} && substr($ITEM{'directory'},-1)!='/' ){$ITEM{'directory'} .= '/';} if ($ITEM{'ext'}){$ITEM{'ext'} = '.' . $ITEM{'ext'};} $file = $ITEM{'directory'} . $ITEM{'name'} . $version_separator . $ITEM{'version'} . $ITEM{'ext'}; } } directory_for_writing($file); if (is_file($file_source)) { $ok = copy($file_source,$file); } if (!$ok) {$file = $file_source;} } return $file; } #::::::::::::::::::::::::::::::::::: function add_values(&$FIELDS,$PARAMS) { # set value for form element from POST array $number_fields = count($FIELDS); for ($i=0; $i<$number_fields; $i++) { if (isset($PARAMS) && !empty($PARAMS)) { foreach ($PARAMS as $key => $VALUE) { if (isset($FIELDS[$i]{'name'}) && $FIELDS[$i]{'name'} == $key) { $FIELDS[$i] = array_merge($FIELDS[$i],$VALUE); break; } } } } } #::::::::::::::::::::::::::::::::::: function table_array($DATA,$CONNECTION,$type='records') { $print_name = 'table_array'; # function creates from form fields arrays grouped by tables for insert into tha database new records AND select new inserted records from the database $NEW = array(); $TABLES = array(); $TABLES[] = $CONNECTION{'main_table'}; $ARRAY = array(); $number = count($DATA); for ($i=0; $i<$number; $i++) { # table name if (!isset($DATA[$i]{'table'})) {$DATA[$i]{'table'} = '' ;} if ($DATA[$i]{'table'} && isset($DATA[$i]{'name'}) && $DATA[$i]{'name'} && strtolower($DATA[$i]{'type'})!='info' && strtolower($DATA[$i]{'type'})!='button') { # table name to populate $table_name = $DATA[$i]{'table'}; if (!in_array($table_name,$TABLES) && !isset($DATA[$i]{'relation'}{'main_table'})){$TABLES[] = $table_name;} if (!isset($ARRAY{$table_name}) || !$ARRAY{$table_name}){$ARRAY{$table_name} = array();} # relation tables if (isset($DATA[$i]{'relation'}) && !isset($ARRAY{$table_name}{'relation'})){$ARRAY{$table_name}{'relation'} = $DATA[$i]{'relation'};} if (!isset($ARRAY{$table_name}{$type})){$ARRAY{$table_name}{$type} = array();} if ($type=='records') # RECORDS (for table update) { # records $record_number = (isset($DATA[$i]{'record'}) && $DATA[$i]{'record'}) ? ($DATA[$i]{'record'} - 1) : 0; if (!isset($ARRAY{$table_name}{$type}[$record_number])){$ARRAY{$table_name}{$type}[$record_number] = array();} # field name list($field_name) = explode('__',$DATA[$i]{'name'}); if ($field_name){$ITEM{$field_name} = (isset($DATA[$i]{'value'})) ? $DATA[$i]{'value'} : '' ;} $ARRAY{$table_name}{'records'}[$record_number]{$field_name} = (isset($DATA[$i]{'value'})) ? $DATA[$i]{'value'} : ''; # hidden fields for record if (!isset($ARRAY{$table_name}{'hidden'}[$record_number])){$ARRAY{$table_name}{'hidden'}[$record_number] = array();} if (strtolower($DATA[$i]{'type'})=='hidden') { if (!in_array($field_name,$ARRAY{$table_name}{'hidden'}[$record_number])){$ARRAY{$table_name}{'hidden'}[$record_number][] = $field_name;} } # check empty record into the database if (!isset($ARRAY{$table_name}{'accept_empty'}[$record_number])){$ARRAY{$table_name}{'accept_empty'}[$record_number] = 0 ;} if (isset($DATA[$i]{'accept_empty'})) # field value can be empty { $ARRAY{$table_name}{'accept_empty'}[$record_number] = $DATA[$i]{'accept_empty'}; } } else # FIELDS (for table query select) { $field_name = (isset($DATA[$i]{'used_for'}) && $DATA[$i]{'used_for'}) ? $DATA[$i]{'used_for'} : $DATA[$i]{'name'}; if (!in_array($field_name,$ARRAY{$table_name}{$type})){$ARRAY{$table_name}{$type}[] = $field_name;} if (strtolower($DATA[$i]{'type'})=='hidden') { if (!isset($ARRAY{$table_name}{'hidden'})){$ARRAY{$table_name}{'hidden'} = array();} if (!in_array($field_name,$ARRAY{$table_name}{'hidden'})){$ARRAY{$table_name}{'hidden'}[] = $field_name;} } } } } if (is_array($ARRAY) && !empty($ARRAY)) { foreach ($ARRAY as $key => $value) { $second_main_table = (isset($ARRAY{$key}{'relation'}{'main_table'})) ? $ARRAY{$key}{'relation'}{'main_table'} : '' ; if ($second_main_table) { $ARRAY{$second_main_table}{'relation'}{$type} = $ARRAY{$key}{$type}; unset($ARRAY{$key}); } } } $NEW{'tables'} = $TABLES; $NEW{'array'} = $ARRAY; return $NEW; } #::::::::::::::::::::::::::::::::::: function forced_to_empty($ARRAY,$FORCED=array()) { $number = count($FORCED); for ($i=0; $i<$number; $i++) { $main_field = $FORCED[$i]{'main'}; if ((!isset($ARRAY{$main_field}) || !trim($ARRAY{$main_field})) && isset($FORCED[$i]{'forced'}) && !empty($FORCED[$i]{'forced'})) { foreach ($ARRAY as $key => $value) { if (in_array($key,$FORCED[$i]{'forced'})){$ARRAY{$key} = '';} } } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function record_into_database($ARRAY,$CONNECTION,$accept_empty_record=0,$ID_field='ID') { $print_name = 'record_into_database'; # correct Identity field for dependent multirecords if (isset($ARRAY{'extra_fields'}{'Identity'}) && $ARRAY{'extra_fields'}{'Identity'}) { if (isset( $ARRAY{'main_ID'}) && $ARRAY{'main_ID'} && isset( $ARRAY{'item'}{$ARRAY{'main_ID'}}) && $ARRAY{'item'}{$ARRAY{'main_ID'}} && isset($ARRAY{'record_number'}) && $ARRAY{'record_number'} ) { $ARRAY{'extra_fields'}{'Identity'} = rand(10,99) . $ARRAY{'record_number'} . $ARRAY{'extra_fields'}{'Identity'}; } } $ITEM = $ARRAY{'item'}; $OTHER_SPECIFY = $ARRAY{'other_specify'}; $table_name = $ARRAY{'table_name'}; $USED = $ARRAY{'used'}; $EXTRA = $ARRAY{'extra_fields'}; $ESSENTIAL = $ARRAY{'essential_fields'}; $FORCED = $ARRAY{'forced_to_empty'}; $EXCEPT = $ARRAY{'except'}; $CRITICAL = $ARRAY{'critical_fields'}; $attempt_table = $ARRAY{'attempt_table'}; $record_number = $ARRAY{'record_number'}; $record_ID = 0; $CHANGED = array(); # handle fileds with 'other-specify' option if (is_array($OTHER_SPECIFY) && !empty($OTHER_SPECIFY)) { field_with_option_other($ITEM,$OTHER_SPECIFY); } # function creates from several form fields one field for database (if needed), function individual to each project # this 'assemble_complex_fields' function individual to each project and determine in 'functions/main.php' for the project if (is_array($USED) && !empty($USED)) { assemble_complex_fields($ITEM,$table_name,$record_number); unset_used_for_fields($ITEM,$USED,$table_name,$record_number); } # add essential fields (ID for updated, etc/) if (is_array($ESSENTIAL) && !empty($ESSENTIAL)) { $ITEM = array_merge($ITEM,$ESSENTIAL); } $type = (isset($ITEM{$ID_field}) && $ITEM{$ID_field}) ? 'Update' : 'Insert' ; # CHECK for EMPTY record (before adding the EXTRA fields) $empty_record = 0; # for UPDATE fields can be empty if (strtolower($type)=='insert' && !$accept_empty_record) { # check empty record for INSERT $empty_record = check_for_empty_entry_insert($ITEM,$FORCED,$EXCEPT,$CRITICAL); } # add extra fields if (is_array($EXTRA) && !empty($EXTRA)) { # add EXTRA fileds if they are not explicitly defined as form fields $KEYS_ITEM = (is_array($ITEM) && !empty($ITEM)) ? array_keys($ITEM) : array(); $KEYS_EXTRA = (is_array($EXTRA) && !empty($EXTRA)) ? array_keys($EXTRA) : array(); if (!empty($KEYS_ITEM) && !empty($KEYS_EXTRA)) { $KEYS_TO_UNSET = array_intersect($KEYS_ITEM,$KEYS_EXTRA); $number = count($KEYS_TO_UNSET); if ($number) { $KEYS_TO_UNSET = array_values($KEYS_TO_UNSET); for ($i=0; $i<$number; $i++) { unset($EXTRA{$KEYS_TO_UNSET[$i]}); } } } $ITEM = array_merge($ITEM,$EXTRA); } if (!$empty_record) { # Insert_DateTime, Update_DateTime etc. $user_login_name = (isset($_SERVER{'PHP_AUTH_USER'}) && $_SERVER{'PHP_AUTH_USER'}) ? $_SERVER{'PHP_AUTH_USER'} : $CONNECTION{'user'}; login_table_track($ITEM,$user_login_name,$type); # target table $target_table = $CONNECTION{'database'} . '.' . $table_name . $attempt_table; # update table if (isset($ITEM{$ID_field}) && $ITEM{$ID_field}) # UPDATE record { # check if updated record is different from existing in the database record $CHANGED = check_for_updated_record($ITEM,$CONNECTION{'database'} . '.' . $table_name,$ITEM{$ID_field}); $record_to_update = (!empty($CHANGED)) ? 1 : 0; if ($record_to_update) # there is NEW info -> record should be updated { $record_ID = update_query($ITEM,$target_table,$ITEM{$ID_field},$ID_field); } } elseif (!isset($empty_record) || !$empty_record) # INSERT into table not empty record { if ($table_name==$CONNECTION{'main_table'} || (isset($ITEM{$CONNECTION{'main_ID'}}) && $ITEM{$CONNECTION{'main_ID'}})) { $record_ID = insert_query($ITEM,$target_table); } } } $OUTPUT = array( 'type' => $type, 'fields' => $CHANGED, 'record_ID' => $record_ID, ); return $OUTPUT; } #::::::::::::::::::::::::::::::::::: function create_array_of_emails($value) { $ARRAY = array(); $NEW = create_an_array($value); $number = count($NEW); for ($i=0; $i<$number; $i++) { $ARRAY = array_merge($ARRAY,find_email($NEW[$i])); } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function email_attachments($ARRAY,&$header,&$message) { $print_name = 'email_attachments'; $number = count($ARRAY); if ($number) { $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $uploaded = 'file'; $attachment = 'attachment'; if ($number>1) { $uploaded .= 's'; $attachment .= 's'; } $header .= "MIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"".$mime_boundary."\""; $message = 'This is a multi-part message in MIME format.' . "\n\n" . '--' . $mime_boundary . "\n" . 'Content-Type: text/plain; charset="iso-8859-1"' . "\n" . 'Content-Transfer-Encoding: 7bit' . "\n\n" . $message . "\n\n"; for ($i=0; $i<$number; $i++) { if (!isset($ARRAY[$i]{'type'}) || !$ARRAY[$i]{'type'}) { $ext = strtolower(file_ext($ARRAY[$i]{'path'})); # type from ext if ($ext=='docx'){$ARRAY[$i]{'type'} = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'; } elseif ($ext=='doc'){$ARRAY[$i]{'type'} = 'application/msword';} elseif ($ext=='odt'){$ARRAY[$i]{'type'} = 'application/vnd.oasis.opendocument.text';} elseif ($ext=='zip'){$ARRAY[$i]{'type'} = 'application/zip';} elseif ($ext=='html' || $ext=='csv'){$ARRAY[$i]{'type'} = 'text/' . $ext;} # images elseif ($ext=='png' || $ext=='gif'){$ARRAY[$i]{'type'} = 'image/' . $ext;} elseif ($ext=='jpg' || $ext=='jpeg'){$ARRAY[$i]{'type'} = 'image/jpeg';} elseif (isset($finfo)) # MIME { $ARRAY[$i]{'type'} = finfo_file($finfo, $ARRAY[$i]{'path'}); if (strstr($ARRAY[$i]{'type'}, ';')) { $ITEM = explode(';',$ARRAY[$i]{'type'}); if (isset($ITEM[0]) && trim($ITEM[0])) { $ARRAY[$i]{'type'} = trim($ITEM[0]); } } } else { $ARRAY[$i]{'type'} = 'application/pdf'; } } $ext = strtolower(file_ext($ARRAY[$i]{'path'})); if (!strstr($ARRAY[$i]{'name'},'.')){$ARRAY[$i]{'name'} .= '.' . $ext;} # read the file $file = fopen( $ARRAY[$i]{'path'}, 'rb' ); $data = fread( $file, filesize( $ARRAY[$i]{'path'} ) ); fclose( $file ); $data = chunk_split(base64_encode($data)); # Add the MIME content $message .= "--".$mime_boundary."\n" . "Content-Type: ".$ARRAY[$i]{'type'}.";\n" . " name=\"".$ARRAY[$i]{'name'}."\"\n" . "Content-Disposition: attachment;\n" . " filename=\"".$ARRAY[$i]{'name'}."\"\n" . "Content-Transfer-Encoding: base64\n\n".$data."\n\n"; } $message .= "--".$mime_boundary."--\n"; if (isset($finfo)){finfo_close($finfo);} } } #::::::::::::::::::::::::::::::::::: function print_variable( $variable,$border=1 ) { # functions prints the variable $empty = 'empty'; print ''; if (is_array($variable)) { print ''; if ((count($variable))>0) { foreach ($variable as $key => $value) { print ''; if (!is_array($value)) { if (empty($value)){$value = $empty;} print ''; } else { print '"; } print ''; } } else {print '';} } else { if (empty($variable)){$variable = $empty;} print ''; } print '
    array keyarray value
    ' . $key . '' . $value . '' . $key . ''; print_variable( $value,0 ); print "
    ' . $empty . '
    ' . $variable . '
    ' . "\n"; } #::::::::::::::::::::::::::::::::::: function create_where($field,$ARRAY,$condition='or',$like=0,$exact_left=0,$exact_right=0,$not=0) { $print_name = 'create_where'; $string = ''; $like_string = ' like'; $sign_string = '='; if ($not) { $like_string = ' not' . $like_string; $sign_string = '!' . $sign_string; } $number = count($ARRAY); for ($i=0; $i<$number; $i++) { $value = $ARRAY[$i]; if ($like) { if (!$exact_left){$value = $value . '%' ;} if (!$exact_right){$value = '%' . $value;} } if ($field!='ID'){$value = ($like) ? $like_string . ' "' . $value . '"' : $sign_string . '"' . $value . '"';} else {$value = $sign_string . $ARRAY[$i];} $ARRAY[$i] = $field . $value ; } if (is_array($ARRAY) && !empty($ARRAY)) { $string = implode($ARRAY,' ' . $condition . ' '); $string = '(' . $string . ')' ; } return $string; } #::::::::::::::::::::::::::::::::::: function aliases_array($QUERY,$edit_alias='') { $print_name = 'aliases_array'; global $PAGE; $ARRAY = array(); # select TRUSTED data $DATA = select_data($QUERY,array(),$untrusted_data=0); $number = count($DATA); for ($i=0; $i<$number; $i++) { if ($DATA[$i]{'Value'}) { if (isset($DATA[$i]{'Type'}) && $DATA[$i]{'Type'}=='text') { $ARRAY{$DATA[$i]{'Name'}} = $DATA[$i]{'Value'}; } elseif (!$DATA[$i]{'Used_From_Function'}) { $eval_value = '$function_value = ' . $DATA[$i]{'Value'} . ';'; eval($eval_value); $ARRAY{$DATA[$i]{'Name'}} = $function_value; } else {$ARRAY{$DATA[$i]{'Name'}} = $DATA[$i]{'Value'};} if (isset($DATA[$i]{'Edit'}) && $DATA[$i]{'Edit'}=='yes' && $edit_alias && isset($DATA[$i]{'ID'}) && $DATA[$i]{'ID'}) { $ARRAY{$DATA[$i]{'Name'}} = '
    EDIT ' . $ARRAY{$DATA[$i]{'Name'}} . '
    '; } } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function genRandomString($length=10) { # generate a random string $print_name = 'genRandomString'; $string = ''; if ($length) { $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters)-1)]; } } return $string; } #::::::::::::::::::::::::::::::::::: function clear_string( $string ) { $string = preg_replace("|\s|",' ',$string); while (strstr($string,' ')){$string = str_replace(' ',' ',$string);} $string = trim($string); return $string; } #::::::::::::::::::::::::::::::::::: function field_length_in_table($database,$table,$FIELDS) { $ARRAY = array(); if ($table) { $Query = " select * from ".$database.".".$table." limit 0"; $Select = mysql_query($Query); if (!$Select) { error_report (); print "
    QUERY:
    ".$Query."
    "; } else { $i = 0; $number_fields = mysql_num_fields($Select); while ($i < $number_fields) { $ARRAY[$i]{'name'} = mysql_field_name($Select,$i); $ARRAY[$i]{'length'} = mysql_field_len($Select,$i); $i++; } $number_array = count($ARRAY); $number = count($FIELDS); for ($i=0; $i<$number; $i++) { if (isset($FIELDS[$i]{'type'}) && $FIELDS[$i]{'type'}=='text') { for ($j=0; $j<$number_array; $j++) { if ($FIELDS[$i]{'name'}==$ARRAY[$j]{'name'}) { $FIELDS[$i]{'length'} = $ARRAY[$j]{'length'}; break; } } } } } } return $FIELDS; } #::::::::::::::::::::::::::::::::::: function verification_field($verify,$verify_step) { $NEW = array(); $add = 0; if ($verify && $verify_step) { if (is_array($verify)) { if (in_array($verify_step,$verify)){$add = 1;} } elseif ($verify=='all'){$add = 1;} if ($add) { $NEW[] = array( 'title' => 'verify', 'name' => 'verify', 'type' => 'Hidden', 'step' => $verify_step, 'value' => $verify_step, ); } } return $NEW; } #::::::::::::::::::::::::::::::::::: function convert_database_date($database_date) { $DATE = database_date_array($database_date); $time = mktime(0,0,0,$DATE{'month'},$DATE{'day'},$DATE{'year'}); return $time; } #::::::::::::::::::::::::::::::::::: function convert_date_to_sort($date) { if (!strstr($date,'.')) { $MONTH = array('January','February','March','April','May','June','July','August','September','October','November','December'); $number = count($MONTH); if (strstr($date,'/')) { list($month,$day,$year) = explode('/',$date); } elseif (strstr($date,',')) { list($month_day,$year) = explode(',',$date); list($month,$day) = explode(' ',$month_day); for ($i=0; $i<$number; $i++) { $month = trim($month); if (stristr($MONTH[$i],$month)){$month = $i+1; break;} } } $year = trim($year); $month = trim($month); $day = trim($day); $year = (integer) $year; $month = (integer) $month; $day = (integer) $day; if ($year < 50){$year += 2000;} elseif ($year < 100){$year += 1900;} if ($month<10){$month = '0' . $month;} if ($day<10){$day = '0' . $day;} $date = $year . '.' . $month . '.' . $day; } return $date; } #::::::::::::::::::::::::::::::::::: function identity_record_from_url($param='') { $print_name = 'identity_record_from_url'; $ARRAY = array(); $PARAMS = param_get(); $ARRAY = array(); if (is_array($PARAMS) && !empty($PARAMS)) { foreach ($PARAMS as $key => $value) { if ($key=='key' || $key=='id' || $key=='ID' || ($param && $key==$param)) { $ARRAY = array('param'=>$key, 'value'=>$value); break; } } if (!empty($ARRAY) && !$ARRAY{'value'} && strtolower($ARRAY{'param'})=='id' && isset($PARAMS{'key'}) && $PARAMS{'key'}) { $ARRAY = array('param'=>'key', 'value'=>$PARAMS{'key'}); } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function record_essential($IDENTITY,$ARRAY) { $print_name = 'record_essential'; $NEW = array(); if (isset($IDENTITY{'param'}) && $IDENTITY{'param'} && isset($IDENTITY{'value'}) && $IDENTITY{'value'}) { if (isset($ARRAY{'table'}) && $ARRAY{'table'}) { $NEW{'table'} = $ARRAY{'table'}; } if ($IDENTITY{'param'}=='key') # not existing dependent record (to add a dependent record) { $NEW{'host_field'} = array('field'=>$ARRAY{'identity'}{'host_field'}, 'value'=>$IDENTITY{'value'} ); } else # existing record (independent or dependent) { $FIELDS = array(); $identity_field = value_in_order($ARRAY{'identity'},array('identity_field','id_field'),'ID',1); if ($identity_field) { $FIELDS[] = $identity_field; $id_field = value_in_order($ARRAY{'identity'},array('id_field'),'ID',1); if ($id_field){$FIELDS[] = $id_field;} $host_field = value_in_order($ARRAY{'identity'},array('host_field'),'',1); if ($host_field){$FIELDS[] = $host_field;} $FIELDS = array_values(array_unique($FIELDS)); $QUERY = array( 'tables' => $ARRAY{'table'}, 'fields' => implode($FIELDS,','), 'where' => $identity_field . '="' . $IDENTITY{'value'} . '"', ); $DATA = select_data($QUERY); if (isset($DATA[0])) { $NEW{'identity_field'} = array('field'=>$identity_field, 'value'=>$DATA[0]{$identity_field}); if ($id_field){$NEW{'id_field'} = array('field'=>$id_field, 'value'=>$DATA[0]{$id_field});} if ($host_field){$NEW{'host_field'} = array('field'=>$host_field, 'value'=>$DATA[0]{$host_field});} } } } } return $NEW; } #::::::::::::::::::::::::::::::::::: function clean_field_name($string) { if (strstr($string,'.')) { $string = strrchr($string,'.'); $string = str_replace('.','',$string); } return $string; } #::::::::::::::::::::::::::::::::::: function next_ID_will_be($table,$id_field) { $print_name = 'next_ID_will_be'; $next_ID = 0; $id_field = clean_field_name($id_field); $QUERY = array( 'tables' => $table, 'fields' => $id_field, 'where' => '', 'order' => $id_field . ' desc', 'limit' => 1, ); $DATA = select_data($QUERY); if (isset($DATA[0]{$id_field})){$next_ID = $DATA[0]{$id_field};} $next_ID ++; return $next_ID; } #::::::::::::::::::::::::::::::::::: function file_directory_name_ext_version($file,$version_separator='_') { $ARRAY = array(); if ($file) { $directory = ''; if (strstr($file,'/')) { $position = strrpos($file,'/') + 1; $ARRAY{'directory'} = substr($file,0,$position); $file = substr($file,$position); } $ARRAY{'ext'} = file_ext($file); $ARRAY{'name'} = str_replace(".".$ARRAY{'ext'}."",'',$file); $version_position = (strstr($ARRAY{'name'},$version_separator)) ? strrpos($ARRAY{'name'},$version_separator) : ''; $ARRAY{'version'} = ''; if ($version_position) { $ARRAY{'version'} = substr($ARRAY{'name'},($version_position+2)) ; $ARRAY{'name'} = substr($ARRAY{'name'},0,$version_position) ; } } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function directory_list(&$LIST,&$DIRECTORY,&$FILE) { $print_name = 'directory_list'; if (!empty($LIST)) { $directory = array_pop($LIST); if (is_dir($directory)) { if (substr($directory,-1,1) != '/'){$directory .= '/';} $handler_dir = opendir($directory); while (false !== ($item = readdir($handler_dir))) { if ($item!='.' && $item!='..') { $item = "".$directory."".$item.""; if (is_dir($item)) { $LIST[] = $item; $DIRECTORY[] = $item; } elseif (is_file($item) && !strstr($item,'~') && !strstr($item,'#') && !strstr($item,'_old')) { $FILE[] = $item; } } directory_list($LIST,$DIRECTORY,$FILE); } } } } #::::::::::::::::::::::::::::::::::: function field_with_option_other(&$DATA,$ARRAY) { $number = count($ARRAY); for ($i=0; $i<$number; $i++) { $FIELD = $ARRAY[$i]; if (isset($DATA{$FIELD{'main'}}) || (isset($DATA{$FIELD{'other'}}) && $DATA{$FIELD{'other'}})) { $DATA{$FIELD{'target'}} = $DATA{$FIELD{'main'}}; $other = trim($DATA{$FIELD{'other'}}); if ($other){$DATA{$FIELD{'target'}} .= " | ".$other."";} unset($DATA{$FIELD{'main'}}); unset($DATA{$FIELD{'other'}}); } } } #::::::::::::::::::::::::::::::::::: function unset_used_for_fields(&$ARRAY,$USED,$table_name,$record_number) { # function unsets temporary ('used_for') form fields unneeded for database if (is_array($USED) && !empty($USED)) { if (is_array($ARRAY) && !empty($ARRAY)) { $ITEM{'table'} = $table_name; $ITEM{'record'} = $record_number; foreach ($ARRAY as $key => $value) { $ITEM{'name'} = $key; $NEW = add_table_and_record(array($ITEM)); if (in_array($NEW[0]{'name'},$USED)) { unset($ARRAY{$key}); } } } } } #::::::::::::::::::::::::::::::::::: function check_for_empty_entry_insert($ARRAY,$FORCED=array(),$EXCEPT=array('ID'),$CRITICAL=array()) { $print_name = 'check_for_empty_entry_insert'; # if one of the critical field is empty => the whole record is empty $empty = 1; $number_critical = count($CRITICAL); for ($i=0 ; $i<$number_critical; $i++) { if (!isset($ARRAY{$CRITICAL[$i]}) || !$ARRAY{$CRITICAL[$i]}) { return $empty; } } $ARRAY = forced_to_empty($ARRAY,$FORCED); if (is_array($ARRAY) && !empty($ARRAY)) { foreach ($ARRAY as $key => $value) { if (trim($value) && !in_array($key,$EXCEPT)) { $empty = 0; break; } } } return $empty; } #::::::::::::::::::::::::::::::::::: function login_table_track(&$ARRAY,$login,$type='Insert') { # adding Login and DateTime fields to track the update $ARRAY{ucfirst(strtolower($type)) . '_Login'} = $login; $ARRAY{ucfirst(strtolower($type)) . '_DateTime'} = date('Y.m.d H:i:s'); } #::::::::::::::::::::::::::::::::::: function check_for_updated_record($ARRAY,$table,$id,$id_field='ID',$EXEPT_FIELDS=array('Update_Login','Update_DateTime')) { # remove unneeded fields $number = count($EXEPT_FIELDS); for ($i=0; $i<$number; $i++) { unset($ARRAY{$EXEPT_FIELDS[$i]}); } $CHANGE = array(); if (is_array($ARRAY) && !empty($ARRAY)) { $FIELDS = array_keys($ARRAY); if (is_array($FIELDS) && !empty($FIELDS)) { $QUERY = array( 'tables' => $table, 'fields' => implode($FIELDS,','), 'where' => $id_field . '="' . $id . '"', ); $DATA = select_data($QUERY,array(),$untrasted_data=0); $OLD = $DATA[0]; if (is_array($OLD) && !empty($OLD)) { foreach ($OLD as $key => $value) { if ($OLD{$key}!=$ARRAY{$key}) { $CHANGE{$key} = array( 'old' => $OLD{$key}, 'new' => $ARRAY{$key}, ); } } } } } return $CHANGE; } #::::::::::::::::::::::::::::::::::: function update_query($ARRAY,$table,$id,$id_field='ID') { $print_name = 'update_query'; global $CONNECTION; $set = ''; $id_result = 0; $connect = database_connection($CONNECTION); if (!$connect) { } else { if (is_array($ARRAY) && !empty($ARRAY) && $table && $id) { $ARRAY{'Update_DateTime'} = date('Y.m.d H:i:s'); $ARRAY{'Update_Login'} = auth_user(); foreach ($ARRAY as $key => $value) { if (strstr($value,'"')) { $value = addcslashes($value,'"'); } if ($set) { $set .= ','; } $set .= $key . '="' . $value . '"'; } $lock = 0; if ($set) { $locking = 'Lock tables ' . $table . ' write'; $LOCK_TABLES = mysqli_query($connect,$locking); if (mysqli_errno($connect)) { printf("Errorcode: %d\n", mysqli_errno($connect)); print '
    locking (' . $print_name . ')' . $locking . '
    '; } else {$lock = 1;} if ($lock) { $Query = 'update ' . $table . ' set ' . $set . ' where ' . $id_field . '="' . $id . '"'; $result = mysqli_query($connect,$Query); if ($result) { } else { if (mysqli_errno($connect)) { printf("Errorcode: %d\n", mysqli_errno($connect)); print '
    Query (' . $print_name . ')' . $Query . '
    '; } } $Unlock = 'Unlock tables'; $lock_mysql = mysqli_query($connect,$Unlock); } else { print '
    table is NOT locked'; printf("Errorcode: %d\n", mysqli_errno($connect)); } } } } return $id; } #::::::::::::::::::::::::::::::::::: function insert_query($ARRAY,$table) { $print_name = 'insert_query'; global $CONNECTION; $id = 0; $fields = ''; $values = ''; $connect = database_connection($CONNECTION); if (!$connect) { } else { if (is_array($ARRAY) && !empty($ARRAY) && $table) { $ARRAY{'Insert_DateTime'} = date('Y.m.d H:i:s'); if (!isset($ARRAY{'Insert_Login'}) || !$ARRAY{'Insert_Login'}){$ARRAY{'Insert_Login'} = auth_user();} foreach ($ARRAY as $key => $value) { if ($value!='' || $key!='ID') # new rule for primary key in mysql 5 (?) { if ($fields) { $fields .= ','; $values .= ','; } $fields .= $key; if (strstr($value,'"')){$value = addcslashes($value,'"');} $values .= '"' . $value . '"'; } } if ($fields && $values) { $Lock = 'Lock tables ' . $table . ' write'; $lock_mysql = mysqli_query($connect,$Lock); if ($lock_mysql) { $Query = 'insert into ' . $table . ' (' . $fields . ') values (' . $values . ')'; $result = mysqli_query($connect,$Query); if ($result){$id = mysqli_insert_id($connect);} else { $id = 0; if (mysqli_errno($connect)) { printf("Errorcode: %d\n", mysqli_errno($connect)); } print '
    Insert Query (insert_query)'; print_variable($Query); } $Unlock = 'Unlock tables'; $lock_mysql = mysqli_query($connect,$Unlock); } else { print '
    LOCK is NOT OK (insert_query)'; if (mysqli_errno($connect)) { printf("Errorcode: %d\n", mysqli_errno($connect)); } } } } } return $id; } #::::::::::::::::::::::::::::::::::: function create_an_array($variable) { $ARRAY = array(); if (is_array($variable)){$ARRAY = $variable; } else {$ARRAY[] = $variable; } return $ARRAY; } #::::::::::::::::::::::::::::::::::: function database_date_array($database_date) { $DATE = array(); $ARRAY = explode('.',$database_date); $year = (isset($ARRAY[0])) ? $ARRAY[0] : ''; $month = (isset($ARRAY[1])) ? $ARRAY[1] : ''; $day = (isset($ARRAY[2])) ? $ARRAY[2] : ''; $DATE{'year'} = ($year) ? (integer) $year : 0; $DATE{'month'} = ($month) ? (integer) $month : 0; $DATE{'day'} = ($day) ? (integer) $day : 0; return $DATE; } #::::::::::::::::::::::::::::::::::: function param_get($param='',$type='get') { $print_name = 'param_get'; $string = ''; $PARAMS = array(); if ($type=='get') { $PARAMS = (isset($_GET)) ? $_GET : array(); } else { $PARAMS = (isset($_POST)) ? $_POST : array(); } if ($param) # particular param { if (isset($PARAMS{$param}) && $PARAMS{$param}) {$string = $PARAMS{$param};} return $string; } else # some param(s) { if (!empty($PARAMS)) { return $PARAMS; } } } #::::::::::::::::::::::::::::::::::: function value_in_order($ARRAY,$FIELDS,$default_field,$value=1) { $number = count($FIELDS); $string = $default_field; if (is_array($ARRAY) && !empty($ARRAY)) { for ($i=0; $i<$number; $i++) { if (isset($ARRAY{$FIELDS[$i]}) && $ARRAY{$FIELDS[$i]}) { if ($value) # not nul value { if ($ARRAY{$FIELDS[$i]}){$string = $ARRAY{$FIELDS[$i]}; break;} } else {$string = $ARRAY{$FIELDS[$i]}; break;} } } } return $string; } #::::::::::::::::::::::::::::::::::: function auth_user($page_type='html') { $print_name = 'auth_user'; global $PAGE; $string = ''; if (isset($_SERVER{'PHP_AUTH_USER'}) && $_SERVER{'PHP_AUTH_USER'}){$string = $_SERVER{'PHP_AUTH_USER'};} elseif (isset($_SERVER{'SERVER_NAME'})) { $string = 'egaltseva'; if ($_SERVER{'SERVER_NAME'}=='localhost' && $page_type=='html') { print '
    user @ localhost (' . $print_name . ')'; print_variable($string); } } return $string; } #::::::::::::::::::::::::::::::::::: ?>