"../",
'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.
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 = '';
}
}
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 .= '
';
$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)=='