. */ /** * @brief Action : Document validation * * Open a modal box to displays the validation form, make the form checks * and loads the result in database. Used by the core (manage_action.php page). * * @file * @author Claire Figueras * @date $date$ * @version $Revision$ * @ingroup apps */ /** * $confirm bool false */ $confirm = false; /** * $etapes array Contains only one etap : form */ $etapes = array('form'); /** * $frm_width Width of the modal (empty) */ $frm_width=''; /** * $frm_height Height of the modal (empty) */ $frm_height = ''; /** * $mode_form Mode of the modal : fullscreen */ $mode_form = 'fullscreen'; $_SESSION['is_multi_contact'] = ''; include('apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'definition_mail_categories.php'); ///////////////////// Pattern to check dates $_ENV['date_pattern'] = "/^[0-3][0-9]-[0-1][0-9]-[1-2][0-9][0-9][0-9]$/"; /** * Gets the path of the file to displays * * @param $res_id String Resource identifier * @param $coll_id String Collection identifier * @return String File path **/ function get_file_path($res_id, $coll_id) { require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_security.php"); $sec = new security(); $view = $sec->retrieve_view_from_coll_id($coll_id); if(empty($view)) { $view = $sec->retrieve_table_from_coll($coll_id); } $db = new Database(); $stmt = $db->query("SELECT docserver_id, path, filename FROM ".$view." WHERE res_id = ?", array($res_id)); $res = $stmt->fetchObject(); $path = preg_replace('/#/', DIRECTORY_SEPARATOR, $res->path); $docserver_id = $res->docserver_id; $filename = $res->filename; $stmt = $db->query("SELECT path_template FROM ".$_SESSION['tablename']['docservers']." WHERE docserver_id = ?", array($docserver_id)); $res = $stmt->fetchObject(); $docserver_path = $res->path_template; return $docserver_path.$path.$filename; } function check_category($coll_id, $res_id) { require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_security.php"); $sec = new security(); $view = $sec->retrieve_view_from_coll_id($coll_id); $db = new Database(); $stmt = $db->query("SELECT category_id FROM ".$view." WHERE res_id = ?", array($res_id)); $res = $stmt->fetchObject(); if(!isset($res->category_id)) { $ind_coll = $sec->get_ind_collection($coll_id); $table_ext = $_SESSION['collections'][$ind_coll]['extensions'][0]; $db->query("INSERT INTO ".$table_ext." (res_id, category_id) VALUES (?, ?)", array($res_id, $_SESSION['coll_categories']['letterbox_coll']['default_category'])); } } /** * Returns the validation form text * * @param $values Array Contains the res_id of the document to validate * @param $path_manage_action String Path to the PHP file called in Ajax * @param $id_action String Action identifier * @param $table String Table * @param $module String Origin of the action * @param $coll_id String Collection identifier * @param $mode String Action mode 'mass' or 'page' * @return String The form content text **/ function get_form_txt($values, $path_manage_action, $id_action, $table, $module, $coll_id, $mode ) { if (preg_match("/MSIE 6.0/", $_SERVER["HTTP_USER_AGENT"])) { $browser_ie = true; $display_value = 'block'; } elseif(preg_match('/msie/i', $_SERVER["HTTP_USER_AGENT"]) && !preg_match('/opera/i', $_SERVER["HTTP_USER_AGENT"]) ) { $browser_ie = true; $display_value = 'block'; } else { $browser_ie = false; $display_value = 'table-row'; } $_SESSION['stockCheckbox']= ''; unset($_SESSION['m_admin']['contact']); $_SESSION['req'] = "action"; $res_id = $values[0]; $_SESSION['doc_id'] = $res_id; // Ouverture de la modal $frm_str = ''; $docLockerCustomPath = 'apps/maarch_entreprise/actions/docLocker.php'; $docLockerPath = $_SESSION['config']['businessappurl'] . '/actions/docLocker.php'; if (is_file($docLockerCustomPath)) require_once $docLockerCustomPath; else if (is_file($docLockerPath)) require_once $docLockerPath; else exit("can't find docLocker.php"); $docLocker = new docLocker($res_id); if (!$docLocker->canOpen()) { $docLockerscriptError = ''; return $docLockerscriptError; } // DocLocker constantly $frm_str .= ''; $docLocker->lock(); require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_security.php"); require_once("apps".DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_business_app_tools.php"); require_once("modules".DIRECTORY_SEPARATOR."basket".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_modules_tools.php"); require_once("apps".DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_types.php"); require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php"); $sec =new security(); $core_tools =new core_tools(); $b = new basket(); $type = new types(); $business = new business_app_tools(); $_SESSION['save_list']['fromValidateMail'] = "true"; $_SESSION['count_view_baskets']=0; if($_SESSION['features']['show_types_tree'] == 'true') { $doctypes = $type-> getArrayStructTypes($coll_id); } else { $doctypes = $type->getArrayTypes($coll_id); } $db = new Database(); $hidden_doctypes = array(); $tmp = $business->get_titles(); $titles = $tmp['titles']; $default_title = $tmp['default_title']; if($core_tools->is_module_loaded('templates')) { $stmt = $db->query("SELECT type_id FROM ".$_SESSION['tablename']['temp_templates_doctype_ext']." WHERE is_generated = 'NULL!!!'"); while($res = $stmt->fetchobject()) { array_push($hidden_doctypes, $res->type_id); } } $today = date('d-m-Y'); if ($core_tools->is_module_loaded('entities')) { $EntitiesIdExclusion = array(); $db = new Database(); if (count($_SESSION['user']['redirect_groupbasket'][$_SESSION['current_basket']['id']][$id_action]['entities']) > 0) { $stmt = $db->query( "SELECT entity_id FROM " . ENT_ENTITIES . " WHERE entity_id not in (" . $_SESSION['user']['redirect_groupbasket'][$_SESSION['current_basket']['id']][$id_action]['entities'] . ") and enabled= 'Y' order by entity_id" ); while ($res = $stmt->fetchObject()) { array_push($EntitiesIdExclusion, $res->entity_id); } } require_once 'modules/entities/class/class_manage_entities.php'; $ent = new entity(); $allEntitiesTree= array(); $allEntitiesTree = $ent->getShortEntityTreeAdvanced( $allEntitiesTree, 'all', '', $EntitiesIdExclusion, 'all' ); //diffusion list in this basket ? if($_SESSION['current_basket']['difflist_type'] == 'entity_id'){ $target_model = 'document.getElementById(\'destination\').options[document.getElementById(\'destination\').selectedIndex]'; $func_load_listdiff_by_entity = 'change_entity(this.options[this.selectedIndex].value, \''.$_SESSION['config']['businessappurl'].'index.php?display=true&module=entities&page=load_listinstance'.'\',\'diff_list_div\', \'indexing\', \''.$display_value.'\', \'\', $(\'category_id\').value);'; }else if($_SESSION['current_basket']['difflist_type'] == 'type_id'){ $target_model = 'document.getElementById(\'type_id\').options[document.getElementById(\'type_id\').selectedIndex]'; $func_load_listdiff_by_type = 'load_listmodel('.$target_model.', \'diff_list_div\', \'indexing\', $(\'category_id\').value);'; }else{ $target_model = 'document.getElementById(\'destination\').options[document.getElementById(\'destination\').selectedIndex]'; $func_load_listdiff_by_entity = 'change_entity(this.options[this.selectedIndex].value, \''.$_SESSION['config']['businessappurl'].'index.php?display=true&module=entities&page=load_listinstance'.'\',\'diff_list_div\', \'indexing\', \''.$display_value.'\', \'\', $(\'category_id\').value);'; } //LOADING LISTMODEL require_once('modules/entities/class/class_manage_listdiff.php'); $diff_list = new diffusion_list(); $load_listmodel = true; $stmt = $db->query("SELECT res_id FROM " . $_SESSION['tablename']['ent_listinstance']." WHERE res_id = ?", array($res_id)); if ($stmt->rowCount() > 0) { $load_listmodel = false; $_SESSION['indexing']['diff_list'] = $diff_list->get_listinstance($res_id); } } //Load Multicontacts //CONTACTS $query = "SELECT c.is_corporate_person, c.is_private, c.contact_lastname, c.contact_firstname, c.society, c.society_short, c.contact_purpose_id, c.address_num, c.address_street, c.address_postal_code, c.address_town, c.lastname, c.firstname, c.contact_id, c.ca_id "; $query .= "FROM view_contacts c, contacts_res cres "; $query .= "WHERE cres.coll_id = 'letterbox_coll' AND cres.res_id = ? AND cast (c.contact_id as varchar) = cres.contact_id AND c.ca_id = cres.address_id"; $stmt = $db->query($query, array($res_id)); $_SESSION['adresses']['to'] = array(); $_SESSION['adresses']['addressid'] = array(); $_SESSION['adresses']['contactid'] = array(); while($res = $stmt->fetchObject()){ if ($res->is_corporate_person == 'Y') { $addContact = $res->society . ' ' ; if (!empty ($res->society_short)) { $addContact .= '('.$res->society_short.') '; } } else { $addContact = $res->contact_lastname . ' ' . $res->contact_firstname . ' '; if (!empty ($res->society)) { $addContact .= '(' .$res->society . ') '; } } if ($res->is_private == 'Y') { $addContact .= '('._CONFIDENTIAL_ADDRESS.')'; } else { require_once("apps".DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_contacts_v2.php"); $contact = new contacts_v2(); $addContact .= '- ' . $contact->get_label_contact($res->contact_purpose_id, $_SESSION['tablename']['contact_purposes']).' : '; if (!empty($res->lastname) || !empty($res->firstname)) { $addContact .= $res->lastname . ' ' . $res->firstname; } if (!empty($res->address_num) || !empty($res->address_street) || !empty($res->address_town) || !empty($res->address_postal_code)) { $addContact .= ', '.$res->address_num .' ' . $res->address_street .' ' . $res->address_postal_code .' ' . strtoupper($res->address_town); } } array_push($_SESSION['adresses']['to'], $addContact); array_push($_SESSION['adresses']['addressid'], $res->ca_id); array_push($_SESSION['adresses']['contactid'], $res->contact_id); } //USERS $query = "SELECT u.firstname, u.lastname, u.user_id "; $query .= "FROM users u, contacts_res cres "; $query .= "WHERE cres.coll_id = 'letterbox_coll' AND cres.res_id = ? AND cast (u.user_id as varchar) = cres.contact_id"; $stmt = $db->query($query, array($res_id)); while($res = $stmt->fetchObject()){ $addContact = $res->firstname . $res->lastname; array_push($_SESSION['adresses']['to'], $addContact); array_push($_SESSION['adresses']['addressid'], 0); array_push($_SESSION['adresses']['contactid'], $res->user_id); } check_category($coll_id, $res_id); $data = get_general_data($coll_id, $res_id, 'minimal'); $frm_str .= '

'._VALIDATE_MAIL.' '._NUM.functions::xssafe($res_id); $frm_str .= '

'; $frm_str .=''; $frm_str .=''; $frm_str .= '
'; $frm_str .= ''; $frm_str .= '
'; $frm_str .= '
'; /*** TOOLBAR ***/ $frm_str .= '
'; $frm_str .= ''; $frm_str .= ''; // HISTORY if ($core_tools->test_service('view_doc_history', 'apps', false)) { $frm_str .= ''; } //NOTE if ($core_tools->is_module_loaded('notes')) { $frm_str .= ''; } //ATTACHMENTS if ($core_tools->is_module_loaded('attachments')) { $frm_str .= ''; } if ($core_tools->is_module_loaded('entities')) { $frm_str .= ''; } //LINKS $frm_str .= ''; //CASES if ($core_tools->is_module_loaded('cases')) { require_once('modules/cases/class/class_modules_tools.php'); $cases = new cases(); $case_id = $cases->get_case_id($res_id); if ($case_id <> false) { $case_properties = $cases->get_case_info($case_id); $style = ''; } else { $case_properties = array(); $style = 'opacity:0.5;'; } $frm_str .= ''; } //END TOOLBAR $frm_str .= '
'; $frm_str .= ''; $frm_str .= ''; $frm_str .= ' '; $frm_str .= ''; $frm_str .= ''; require_once 'modules/notes/class/class_modules_tools.php'; $notes_tools = new notes(); //Count notes $nbr_notes = $notes_tools->countUserNotes($res_id, $coll_id); if ($nbr_notes == 0){ $class = 'nbResZero'; $style2 = 'display:none'; $style = 'opacity:0.5;'; } else{ $class = 'nbRes'; $style = ''; $style2 = ''; } $frm_str .= ''; $frm_str .= '' . '  '.$nbr_notes.''; $frm_str .= ''; $frm_str .= ''; $db = new Database; $stmt = $db->query("SELECT res_id FROM " . $_SESSION['tablename']['attach_res_attachments'] . " WHERE status <> 'DEL' and attachment_type <> 'converted_pdf' and attachment_type <> 'print_folder' and res_id_master = ? and coll_id = ? and (status <> 'TMP' or (typist = ? and status = 'TMP'))", array($res_id, $coll_id, $_SESSION['user']['UserId'])); if ($stmt->rowCount() > 0) { $nb_attach = $stmt->rowCount(); $style = ''; $style2 = ''; }else{ $style = 'opacity:0.5;'; $style2 = 'display:none;'; } if ($answer <> '') { $answer .= ': '; } $frm_str .= ''; $frm_str .= '' . '  '. $nb_attach . ''; $frm_str .= ''; $frm_str .= ''; $frm_str .= ''; $frm_str .= ''; $frm_str .= ' '; $frm_str .= ''; $frm_str .= ''; require_once('core/class/LinkController.php'); $Class_LinkController = new LinkController(); $nbLink = $Class_LinkController->nbDirectLink( $res_id, $coll_id, 'all' ); if ($nbLink == 0) { $class = 'nbResZero'; $style2 = 'display:none'; $style = 'opacity:0.5;'; }else{ $class = 'nbRes'; $style = ''; $style2 = ''; } $frm_str .= ''; $frm_str .= '' . '  ' . $nbLink . ''; $frm_str .= ''; $frm_str .= ''; $frm_str .= ''; $frm_str .= '  '; $frm_str .= ' '; $frm_str .= ''; $frm_str .= '
'; $frm_str .= '
'; $frm_str .= '
'; //FRAME FOR TOOLS /**** Contact form start *******/ if ($core->test_admin('my_contacts', 'apps', false)) { $frm_str .= ''; } /**** Contact form end *******/ /**** Folder form start *******/ if ($core->test_service('create_folder', 'folder', false) == 1) { $frm_str .= ''; } /**** Folder form end *******/ /**** Contact info start *******/ $frm_str .= ''; /**** Contact info end *******/ $frm_str .= ''; //HISTORY FRAME $frm_str .= ''; //CASES FRAME if ($core_tools->is_module_loaded('cases')) { if (!isset($case_properties['case_id'])) { $case_properties = array(); $case_properties['case_id'] = ''; $case_properties['case_label'] = ''; $case_properties['case_description'] = ''; } $frm_str .= ''; } //NOTES if ($core_tools->is_module_loaded('notes')) { //Iframe notes $frm_str .= ''; } //ATTACHMENTS if ($core_tools->is_module_loaded('attachments')) { require 'modules/templates/class/templates_controler.php'; $templatesControler = new templates_controler(); $templates = array(); $templates = $templatesControler->getAllTemplatesForProcess($data['destination']); $_SESSION['destination_entity'] = $data['destination']; $frm_str .= ''; } if ($core_tools->is_module_loaded('entities')) { $frm_str .= ''; } //LINKS $frm_str .= ''; //DOCUMENT VIEWER $path_file = get_file_path($res_id, $coll_id); $frm_str .= ''; //END RIGHT DIV $frm_str .= '
'; /*** Extra javascript ***/ $frm_str .= ''; $frm_str .= ''; return addslashes($frm_str); } /** * Checks the action form * * @param $form_id String Identifier of the form to check * @param $values Array Values of the form * @return Bool true if no error, false otherwise **/ function check_form($form_id,$values) { $_SESSION['action_error'] = ''; if(count($values) < 1 || empty($form_id)) { $_SESSION['action_error'] = _FORM_ERROR; return false; } else { $attach = get_value_fields($values, 'attach'); $coll_id = get_value_fields($values, 'coll_id'); if ($attach) { $idDoc = get_value_fields($values, 'res_id'); if (! $idDoc || empty($idDoc)) { $_SESSION['action_error'] .= _LINK_REFERENCE . '
'; } if (! empty($_SESSION['action_error'])) { return false; } } $cat_id = get_value_fields($values, 'category_id'); if($cat_id == false) { $_SESSION['action_error'] = _CATEGORY.' '._IS_EMPTY; return false; } $no_error = process_category_check($cat_id, $values); return $no_error; } } /** * Checks the values of the action form for a given category * * @param $cat_id String Category identifier * @param $values Array Values of the form to check * @return Bool true if no error, false otherwise **/ function process_category_check($cat_id, $values) { $core = new core_tools(); // If No category : Error if(!isset($_ENV['categories'][$cat_id])) { $_SESSION['action_error'] = _CATEGORY.' '._UNKNOWN.': '.$cat_id; return false; } // Simple cases for($i=0; $i 'integer') { $_SESSION['action_error'] = $_ENV['categories'][$cat_id][$values[$i]['ID']]['label'].' '._IS_EMPTY; return false; } if($_ENV['categories'][$cat_id][$values[$i]['ID']]['type_form'] == 'date' && !empty($values[$i]['VALUE']) && preg_match($_ENV['date_pattern'],$values[$i]['VALUE'])== 0) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id][$values[$i]['ID']]['label']." "._WRONG_FORMAT.""; return false; } if($_ENV['categories'][$cat_id][$values[$i]['ID']]['type_form'] == 'integer' && (!empty($values[$i]['VALUE']) || $values[$i]['VALUE'] == 0) && preg_match("/^[0-9]*$/",$values[$i]['VALUE'])== 0) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id][$values[$i]['ID']]['label']." "._WRONG_FORMAT.""; return false; } if($_ENV['categories'][$cat_id][$values[$i]['ID']]['type_form'] == 'radio' && !empty($values[$i]['VALUE']) && !in_array($values[$i]['VALUE'], $_ENV['categories'][$cat_id][$values[$i]['ID']]['values'])) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id][$values[$i]['ID']]['label']." "._WRONG_FORMAT.""; return false; } } ///// Checks the complementary indexes depending on the doctype require_once('apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_types.php'); $type = new types(); $type_id = get_value_fields($values, 'type_id'); /*if($type_id == 1) { $_SESSION['action_error'] = _TYPE." "._WRONG_FORMAT.""; return false; }*/ $coll_id = get_value_fields($values, 'coll_id'); $indexes = $type->get_indexes( $type_id,$coll_id, 'minimal'); $val_indexes = array(); for($i=0; $icheck_indexes($type_id, $coll_id,$val_indexes ); if(!$test_type) { $_SESSION['action_error'] .= $_SESSION['error']; $_SESSION['error'] = ''; return false; } ///////////////////////// Other cases //doc date /*$doc_date = get_value_fields($values, 'doc_date'); $admission_date = get_value_fields($values, 'admission_date'); if ($admission_date < $doc_date) { $_SESSION['action_error'] = "La date du courrier doit être antérieure à la date d'arrivée du courrier "; return false; }*/ // Process limit Date $_SESSION['store_process_limit_date'] = ""; if(isset($_ENV['categories'][$cat_id]['other_cases']['process_limit_date'])) { $process_limit_date_use_yes = get_value_fields($values, 'process_limit_date_use_yes'); $process_limit_date_use_no = get_value_fields($values, 'process_limit_date_use_no'); if($process_limit_date_use_yes == 'yes') { $_SESSION['store_process_limit_date'] = "ok"; $process_limit_date = get_value_fields($values, 'process_limit_date'); if(trim($process_limit_date) == "" || preg_match($_ENV['date_pattern'], $process_limit_date)== 0) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['process_limit_date']['label']." "._WRONG_FORMAT.""; return false; } } elseif($process_limit_date_use_no == 'no') { $_SESSION['store_process_limit_date'] = "ko"; } $process_limit_date = new datetime($process_limit_date); $process_limit_date = date_add($process_limit_date,date_interval_create_from_date_string('23 hours + 59 minutes + 59 seconds')); } if (isset($_ENV['categories'][$cat_id]['priority'])) { $priority = get_value_fields( $values, 'priority' ); if ($priority === '') { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['priority']['label'] . " " . _MANDATORY; return false; } } // Contact if(isset($_ENV['categories'][$cat_id]['other_cases']['contact'])){ $contact_type = get_value_fields($values, 'type_contact_external'); if(!$contact_type) { $contact_type = get_value_fields($values, 'type_contact_internal'); } if (!$contact_type) { $contact_type = get_value_fields($values, 'type_multi_contact_external'); } if(!$contact_type){ $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['type_contact']['label']." "._MANDATORY.""; return false; } $contact = get_value_fields($values, 'contactid'); $nb_multi_contact = count($_SESSION['adresses']['to']); $contact_field = get_value_fields($values, 'contact'); if ($contact_field <> "" && empty($contact)) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['contact']['label'] . ' ' . _WRONG_FORMAT . ". " . _USE_AUTOCOMPLETION; return false; } if($_ENV['categories'][$cat_id]['other_cases']['contact']['mandatory'] == true) { if((empty($contact) && $contact_type != 'multi_external') || ($nb_multi_contact == 0 && $contact_type == 'multi_external')) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['contact']['label'].' '._IS_EMPTY; return false; } } // if(!empty($contact) ) // { // if($contact_type == 'external' && !preg_match('/\(\d+\)$/', trim($contact))) // { // $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['contact']['label']." "._WRONG_FORMAT.".
".' '._USE_AUTOCOMPLETION; // return false; // } // elseif($contact_type == 'internal' && preg_match('/\([A-Za-Z0-9-_ ]+\)$/', $contact) == 0) // elseif($contact_type == 'internal' && preg_match('/\((.|\s|\d|\h|\w)+\)$/i', $contact) == 0) // if($contact_type == 'internal' && preg_match('/\((.|\s|\d|\h|\w)+\)$/i', $contact) == 0) // { // $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['contact']['label']." "._WRONG_FORMAT.".
"._USE_AUTOCOMPLETION; // return false; // } // } } if($core->is_module_loaded('entities')) { // Diffusion list if(isset($_ENV['categories'][$cat_id]['other_cases']['diff_list']) && $_ENV['categories'][$cat_id]['other_cases']['diff_list']['mandatory'] == true) { if(empty($_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id']) || !isset($_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id'])) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['diff_list']['label']." "._MANDATORY.""; return false; } } } if($core->is_module_loaded('folder')) { $db = new Database(); $folder_id = ''; $folder_id = get_value_fields($values, 'folder'); if(isset($_ENV['categories'][$cat_id]['other_cases']['folder']) && $_ENV['categories'][$cat_id]['other_cases']['folder']['mandatory'] == true) { if(empty($folder)) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['folder']['label'].' '._IS_EMPTY; return false; } } /*if(!empty($folder) ) { if(!preg_match('/\([0-9]+\)$/', $folder)) { $_SESSION['action_error'] = $_ENV['categories'][$cat_id]['other_cases']['folder']['label']." "._WRONG_FORMAT.""; return false; } $folder_id = str_replace(')', '', substr($folder, strrpos($folder,'(')+1)); $stmt = $db->query("SELECT folders_system_id FROM ".$_SESSION['tablename']['fold_folders']." WHERE folders_system_id = ?", array($folder_id)); if($stmt->rowCount() == 0) { $_SESSION['action_error'] = _FOLDER.' '.$folder_id.' '._UNKNOWN; return false; } }*/ if(!empty($type_id ) && !empty($folder_id)) { $foldertype_id = ''; $stmt = $db->query("SELECT foldertype_id FROM ".$_SESSION['tablename']['fold_folders']." WHERE folders_system_id = ?", array($folder_id)); $res = $stmt->fetchObject(); $foldertype_id = $res->foldertype_id; $stmt = $db->query("SELECT fdl.foldertype_id FROM " .$_SESSION['tablename']['fold_foldertypes_doctypes_level1']." fdl, " .$_SESSION['tablename']['doctypes']." d WHERE d.doctypes_first_level_id = fdl.doctypes_first_level_id and fdl.foldertype_id = ? and d.type_id = ".$type_id , array($foldertype_id)); if($stmt->rowCount() == 0) { $_SESSION['action_error'] .= _ERROR_COMPATIBILITY_FOLDER; return false; } } } return true; } /** * Get the value of a given field in the values returned by the form * * @param $values Array Values of the form to check * @param $field String the field * @return String the value, false if the field is not found **/ function get_value_fields($values, $field) { for($i=0; $iretrieve_table_from_coll($coll_id); $ind_coll = $sec->get_ind_collection($coll_id); $table_ext = $_SESSION['collections'][$ind_coll]['extensions'][0]; $res_id = $arr_id[0]; $attach = get_value_fields($values_form, 'attach'); if ($core->is_module_loaded('tags')) { $tags_list = get_value_fields($values_form, 'tag_userform'); $tags_list = explode('__', $tags_list); include_once("modules".DIRECTORY_SEPARATOR."tags" .DIRECTORY_SEPARATOR."tags_update.php"); } //thesaurus if ($core->is_module_loaded('thesaurus')) { require_once 'modules' . DIRECTORY_SEPARATOR . 'thesaurus' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_modules_tools.php'; $thesaurus = new thesaurus(); $thesaurusList = get_value_fields($values_form, 'thesaurus'); $thesaurus->updateResThesaurusList($thesaurusList,$res_id); } $query_ext = "update ".$table_ext." set "; $query_res = "update ".$table." set "; $arrayPDOres = array(); $arrayPDOext = array(); $cat_id = get_value_fields($values_form, 'category_id'); $query_ext .= " category_id = ? " ; $arrayPDOext = array_merge($arrayPDOext, array($cat_id)); //$query_res .= " status = 'NEW' " ; // Specific indexes : values from the form // Simple cases for($i=0; $i 'none') { if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'res') { $query_res .= ", ".$values_form[$i]['ID']." = ? "; $arrayPDOres = array_merge($arrayPDOres, array($values_form[$i]['VALUE'])); } else if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'coll_ext') { $query_ext .= ", ".$values_form[$i]['ID']." = ? "; $arrayPDOext = array_merge($arrayPDOext, array($values_form[$i]['VALUE'])); } } else if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['type_field'] == 'string' && $_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] <> 'none') { if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'res') { $query_res .= ", ".$values_form[$i]['ID']." = ?"; $arrayPDOres = array_merge($arrayPDOres, array($values_form[$i]['VALUE'])); } else if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'coll_ext') { $query_ext .= ", ".$values_form[$i]['ID']." = ?"; $arrayPDOext = array_merge($arrayPDOext, array($values_form[$i]['VALUE'])); } } else if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['type_field'] == 'date' && $_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] <> 'none') { if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'res') { $query_res .= ", ".$values_form[$i]['ID']." = ?"; $arrayPDOres = array_merge($arrayPDOres, array($values_form[$i]['VALUE'])); } else if($_ENV['categories'][$cat_id][$values_form[$i]['ID']]['table'] == 'coll_ext') { $query_ext .= ", ".$values_form[$i]['ID']." = ?"; $arrayPDOext = array_merge($arrayPDOext, array($values_form[$i]['VALUE'])); } } } $status_id = get_value_fields($values_form, 'status'); if (empty($status_id) || $status_id === "") { $status_id = 'BAD'; } else { $query_res .= ", status = ?"; $arrayPDOres = array_merge($arrayPDOres, array($status_id)); } ///////////////////////// Other cases require_once('apps'.DIRECTORY_SEPARATOR.$_SESSION['config']['app_id'].DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_types.php'); $type = new types(); $type->inits_opt_indexes($coll_id, $res_id); $type_id = get_value_fields($values_form, 'type_id'); $indexes = $type->get_indexes( $type_id,$coll_id, 'minimal'); $val_indexes = array(); for($i=0; $iget_sql_update($type_id, $coll_id, $val_indexes); // Confidentiality $confidentiality_yes = get_value_fields($values_form, 'confidential'); if (!empty($confidentiality_yes)) { $query_res .= ", confidentiality = ?"; $arrayPDOres = array_merge($arrayPDOres, array($confidentiality_yes)); } else { $confidentiality_no = get_value_fields($values_form, 'no_confidential'); $query_res .= ", confidentiality = ?"; $arrayPDOres = array_merge($arrayPDOres, array($confidentiality_no)); } // Process limit Date if(isset($_ENV['categories'][$cat_id]['other_cases']['process_limit_date'])) { $process_limit_date = get_value_fields($values_form, 'process_limit_date'); $process_limit_date = new datetime($process_limit_date); $process_limit_date = date_add($process_limit_date,date_interval_create_from_date_string('23 hours + 59 minutes + 59 seconds')); $process_limit_date = (array) $process_limit_date; if($_ENV['categories'][$cat_id]['other_cases']['process_limit_date']['table'] == 'res') { $query_res .= ", process_limit_date = '".$db->format_date_db($process_limit_date['date'],'true','','true')."'"; } else if($_ENV['categories'][$cat_id]['other_cases']['process_limit_date']['table'] == 'coll_ext') { if($_SESSION['store_process_limit_date'] == "ok") { $query_ext .= ", process_limit_date = '".$db->format_date_db($process_limit_date['date'],'true','','true')."'"; } else { $query_ext .= ", process_limit_date = null"; } $_SESSION['store_process_limit_date'] = ""; } } // Contact if(isset($_ENV['categories'][$cat_id]['other_cases']['contact'])) { $contact = get_value_fields($values_form, 'contact'); $contact_type = get_value_fields( $values_form, 'type_contact_external'); if(!$contact_type){ $contact_type = get_value_fields( $values_form, 'type_contact_internal'); } if (!$contact_type) { $contact_type = get_value_fields( $values_form, 'type_multi_contact_external' ); } $nb_multi_contact = count($_SESSION['adresses']['to']); $db->query("DELETE FROM contacts_res where res_id = ?", array($res_id)); $db->query("UPDATE ". $table_ext . " SET exp_user_id = NULL, dest_user_id = NULL, exp_contact_id = NULL, dest_contact_id = NULL where res_id = ?", array($res_id)); if($nb_multi_contact > 0 && $contact_type == 'multi_external'){ for($icontact = 0; $icontact<$nb_multi_contact; $icontact++){ $db->query("INSERT INTO contacts_res (coll_id, res_id, contact_id, address_id) VALUES (?, ?, ?, ?)", array($coll_id, $res_id, $_SESSION['adresses']['contactid'][$icontact], $_SESSION['adresses']['addressid'][$icontact])); } $query_ext .= ", is_multicontacts = 'Y'"; } else{ $contact_id = get_value_fields( $values_form, 'contactid' ); if(!ctype_digit($contact_id)){ $contact_type = 'internal'; }else{ $contact_type = 'external'; } // $contact_id = str_replace(')', '', substr($contact, strrpos($contact,'(')+1)); if($contact_type == 'internal') { if($cat_id == 'incoming' || $cat_id == 'internal' || $cat_id == 'ged_doc') { $query_ext .= ", exp_user_id = ?"; $arrayPDOext = array_merge($arrayPDOext, array($contact_id)); } else if($cat_id == 'outgoing') { $query_ext .= ", dest_user_id = ?"; $arrayPDOext = array_merge($arrayPDOext, array($contact_id)); } $db->query("DELETE FROM contacts_res where res_id = ?", array($res_id)); $query_ext .= ", is_multicontacts = ''"; } elseif($contact_type == 'external') { if($cat_id == 'incoming' || $cat_id == 'ged_doc') { $query_ext .= ", exp_contact_id = ?"; $arrayPDOext = array_merge($arrayPDOext, array($contact_id)); } else if($cat_id == 'outgoing' || $cat_id == 'internal') { $query_ext .= ", dest_contact_id = ?"; $arrayPDOext = array_merge($arrayPDOext, array($contact_id)); } $addressId = get_value_fields( $values_form, 'addressid' ); $query_ext .= ", address_id = ?"; $arrayPDOext = array_merge($arrayPDOext, array($addressId)); $db->query("DELETE FROM contacts_res where res_id = ?", array($res_id)); $query_ext .= ", is_multicontacts = ''"; } } } if($core->is_module_loaded('folder') && ($core->test_service('associate_folder', 'folder',false) == 1)) { $folder_id = ''; $stmt = $db->query("SELECT folders_system_id FROM ".$table ." WHERE res_id = ?", array($res_id)); $res = $stmt->fetchObject(); $old_folder_id = $res->folders_system_id; $folder_id = get_value_fields($values_form, 'folder'); if(!empty($folder_id)) { $query_res .= ", folders_system_id = ?"; $arrayPDOres = array_merge($arrayPDOres, array($folder_id)); } else if(empty($folder_id) && !empty($old_folder_id)) { $query_res .= ", folders_system_id = NULL"; } if($folder_id <> $old_folder_id && $_SESSION['history']['folderup']) { require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_history.php"); $hist = new history(); $hist->add($_SESSION['tablename']['fold_folders'], $folder_id, "UP", 'folderup', _DOC_NUM.$res_id._ADDED_TO_FOLDER, $_SESSION['config']['databasetype'],'apps'); if(isset($old_folder_id) && !empty($old_folder_id)) { $hist->add($_SESSION['tablename']['fold_folders'], $old_folder_id, "UP", 'folderup', _DOC_NUM.$res_id._DELETED_FROM_FOLDER, $_SESSION['config']['databasetype'],'apps'); } } } if($core->is_module_loaded('entities')) { // Diffusion list $load_list_diff = false; if(isset($_ENV['categories'][$cat_id]['other_cases']['diff_list']) ) { if(!empty($_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id']) && isset($_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id'])) { $query_res .= ", dest_user = ?"; $arrayPDOres = array_merge($arrayPDOres, array($_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id'])); } $load_list_diff = true; } } $query_res = preg_replace('/set ,/', 'set ', $query_res); //$query_res = substr($query_res, strpos($query_string, ',')); $arrayPDOres = array_merge($arrayPDOres, array($res_id)); $db->query($query_res." where res_id = ? ", $arrayPDOres); $arrayPDOext = array_merge($arrayPDOext, array($res_id)); $db->query($query_ext." where res_id = ?", $arrayPDOext); if($core->is_module_loaded('entities')) { if($load_list_diff) { require_once('modules'.DIRECTORY_SEPARATOR.'entities'.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_manage_listdiff.php'); $diff_list = new diffusion_list(); $params = array( 'mode'=> 'listinstance', 'table' => $_SESSION['tablename']['ent_listinstance'], 'coll_id' => $coll_id, 'res_id' => $res_id, 'user_id' => $_SESSION['user']['UserId'], 'fromQualif' => true ); $diff_list->load_list_db($_SESSION['indexing']['diff_list'], $params); } } //Create chrono number //###### if ($cat_id == 'outgoing') { $queryChrono = "SELECT alt_identifier FROM " . $table_ext . " WHERE res_id = ?"; $stmt = $db->query($queryChrono, array($res_id)); $resultChrono = $stmt->fetchObject(); if ($resultChrono->alt_identifier == '' OR $resultChrono->alt_identifier == NULL) { require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_chrono.php'; $cTypeId = get_value_fields($values_form, 'type_id'); $cEntity = get_value_fields($values_form, 'destination'); $cChronoOut = get_value_fields($values_form, 'chrono_number'); $chronoX = new chrono(); $myVars = array( 'entity_id' => $cEntity, 'type_id' => $cTypeId, 'category_id' => $cat_id, ); $myForm = array( 'chrono_out' => $cChronoOut, ); $myChrono = $chronoX->generate_chrono($cat_id, $myVars, $myForm); if ($myChrono <> '' && $cChronoOut == '') { $db->query("UPDATE " . $table_ext ." SET alt_identifier = ? WHERE res_id = ? ", array($myChrono, $res_id)); } } } elseif ($cat_id == 'incoming' || $cat_id == 'internal' ) { $queryChrono = "SELECT alt_identifier FROM " . $table_ext . " WHERE res_id = ?"; $stmt = $db->query($queryChrono, array($res_id)); $resultChrono = $stmt->fetchObject(); if ($resultChrono->alt_identifier == '' OR $resultChrono->alt_identifier == NULL) { require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_chrono.php'; $cTypeId = get_value_fields($values_form, 'type_id'); $cEntity = get_value_fields($values_form, 'destination'); $cChronoOut = get_value_fields($values_form, 'chrono_number'); $chronoX = new chrono(); $myVars = array( 'entity_id' => $cEntity, 'type_id' => $cTypeId, 'category_id' => $cat_id, 'res_id' => $res_id ); //print_r($myVars); $myForm = array( 'chrono_out' => $cChronoOut, ); $myChrono = $chronoX->generate_chrono($cat_id, $myVars, $myForm); if ($myChrono <> '') { $db->query("UPDATE " . $table_ext ." SET alt_identifier = ? where res_id = ?", array($myChrono, $res_id)); } } } //$_SESSION['indexing'] = array(); unset($_SESSION['upfile']); //$_SESSION['indexation'] = true; return array('result' => $res_id.'#', 'history_msg' => ''); }