. */ /** * @brief Action : indexing a file * * Open a modal box to displays the indexing 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 */ //$_SESSION['validStep'] = "ko"; include_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'definition_mail_categories.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_security.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'core_tables.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_request.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_resource.php'; require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_business_app_tools.php'; require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_types.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_indexing_searching_app.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'docservers_controler.php'; require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_chrono.php'; require_once 'core' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_history.php'; require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_contacts_v2.php'; $_SESSION['is_multi_contact'] = ''; unset($_SESSION['m_admin']['contact']); $core = new core_tools(); $contacts_v2 = new contacts_v2(); if ($core->is_module_loaded('entities')) { require_once 'modules/entities/entities_tables.php'; } if ($core->is_module_loaded('folder')) { require_once 'modules/folder/folder_tables.php'; } require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'apps_tables.php'; /** * $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'; /** * Returns the indexing form text * * @param $values Array Not used here * @param $pathManageAction String Path to the PHP file called in Ajax * @param $actionId String Action identifier * @param $table String Table * @param $module String Origin of the action * @param $collId String Collection identifier * @param $mode String Action mode 'mass' or 'page' * @return String The form content text **/ function get_form_txt($values, $pathManageAction, $actionId, $table, $module, $collId, $mode ) { $_SESSION['category_id'] = ''; if (preg_match("/MSIE 6.0/", $_SERVER["HTTP_USER_AGENT"])) { $ieBrowser = true; $displayValue = 'block'; } else if (preg_match('/msie/i', $_SERVER["HTTP_USER_AGENT"]) && ! preg_match('/opera/i', $_SERVER["HTTP_USER_AGENT"]) ) { $ieBrowser = true; $displayValue = 'block'; } else { $ieBrowser = false; $displayValue = 'table-row'; } //DECLARATIONS //INSTANTIATE $type = new types(); $core = new core_tools(); $db = new Database(); //INITIALIZE $frmStr = ''; $_SESSION['req'] = "action"; $resId = $values[0]; $today = date('d-m-Y'); $statuses = array(); $_SESSION['adresses']['to'] = array(); $_SESSION['adresses']['contactid'] = array(); $_SESSION['adresses']['addressid'] = array(); if ($_SESSION['features']['show_types_tree'] == 'true') { $doctypes = $type->getArrayStructTypes($collId); } else { $doctypes = $type->getArrayTypes($collId); } if ($core->is_module_loaded('entities')) { require_once 'modules' . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_manage_entities.php'; $ent = new entity(); $allEntitiesTree= array(); $EntitiesIdExclusion = array(); if (count($_SESSION['user']['redirect_groupbasket'][$_SESSION['current_basket']['id']][$actionId]['entities']) > 0) { $stmt = $db->query( "SELECT entity_id FROM " . ENT_ENTITIES . " WHERE entity_id not in (" . $_SESSION['user']['redirect_groupbasket'][$_SESSION['current_basket']['id']][$actionId]['entities'] . ") and enabled= 'Y' order by entity_id" ); while ($res = $stmt->fetchObject()) { array_push($EntitiesIdExclusion, $res->entity_id); } } //diffusion list in this basket ? if($_SESSION['current_basket']['difflist_type'] == 'entity_id'){ $target_model = 'document.getElementById(\'destination\').options[document.getElementById(\'destination\').selectedIndex]'; }else if($_SESSION['current_basket']['difflist_type'] == 'type_id'){ $target_model = 'document.getElementById(\'type_id\').options[document.getElementById(\'type_id\').selectedIndex]'; $func_load_listdiff = 'load_listmodel('.$target_model.', \'diff_list_div\', \'indexing\', $(\'category_id\').value);'; }else{ $target_model = 'document.getElementById(\'destination\').options[document.getElementById(\'destination\').selectedIndex]'; } //var_dump($EntitiesIdExclusion); $allEntitiesTree = $ent->getShortEntityTreeAdvanced( $allEntitiesTree, 'all', '', $EntitiesIdExclusion, 'all' ); } // Select statuses from groupbasket /* Basket of ABS users */ if($_SESSION['current_basket']['abs_basket']=='1'){ $query="SELECT group_id FROM usergroup_content WHERE user_id=? AND primary_group='Y'"; $stmt = $db->query($query, array($_SESSION['current_basket']['basket_owner'])); $grp_status=$stmt->fetchObject(); $owner_usr_grp=$grp_status->group_id; $owner_basket_id=str_replace("_".$_SESSION['current_basket']['basket_owner'], "", $_SESSION['current_basket']['id']); }else{ $owner_usr_grp=$_SESSION['user']['primarygroup']; $owner_basket_id=$_SESSION['current_basket']['id']; } $query = "SELECT status_id, label_status FROM " . GROUPBASKET_STATUS . " left join " . $_SESSION['tablename']['status'] . " on status_id = id " . " WHERE basket_id= ? and (group_id = ? OR group_id in (select group_id from user_baskets_secondary where user_id = ? and basket_id = ?)) and action_id = ?"; $stmt = $db->query($query, array($owner_basket_id, $owner_usr_grp, $_SESSION['user']['UserId'], $owner_basket_id, $actionId)); if($stmt->rowCount() > 0) { while($status = $stmt->fetchObject()) { $statuses[] = array( 'ID' => $status->status_id, 'LABEL' => functions::show_string($status->label_status) ); } } $frmStr .= '

' . _INDEXING_MLB; $frmStr .= '

'; $frmStr .=''; $frmStr .=''; $frmStr .= '
'; $frmStr .= ''; $frmStr .= '
'; $frmStr .= ''; /*** Frame to display the doc ***/ $frmStr .= '
'; $frmStr .='
'; $frmStr .= ''; //$frmStr .= ''; if ($_SESSION['origin'] == "scan") { $frmStr .= ''; } else { $frmStr .= ''; } $frmStr .= '
'; /*** Extra javascript ***/ $frmStr .= ''; $frmStr .= ''; return addslashes($frmStr); } /** * Checks the action form * * @param $formId 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($formId, $values) { if ($_SESSION['upfile']['format']=='maarch'){ $_SESSION['upfile']=''; $_SESSION['upfile']['error']='0'; $_SESSION['upfile']['format']='maarch'; } elseif (empty($_SESSION['upfile']['format'])) { $_SESSION['action_error'] = _FILE . ' ' . _MANDATORY; return false; } //print_r($values); $_SESSION['action_error'] = ''; if (count($values) < 1 || empty($formId)) { $_SESSION['action_error'] = _FORM_ERROR; return false; } else { //print_r($values); $attach = get_value_fields($values, 'attach'); $collId = 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; } } $catId = get_value_fields($values, 'category_id'); if (! $catId) { $_SESSION['action_error'] = _CATEGORY . ' ' . _IS_EMPTY; return false; } $noError = process_category_check($catId, $values); if ($noError == false) { //$_SESSION['action_error'] .= _ERROR_CATEGORY; return false; } if (isset($_SESSION['upfile']['format']) && $_SESSION['upfile']['format'] <> 'maarch' ) { $is = new indexing_searching_app(); $state = $is->is_filetype_allowed( $_SESSION['upfile']['format'] ); if (! $state) { $_SESSION['action_error'] .= '
' . $_SESSION['upfile']['format'] . _FILETYPE . ' ' . _NOT_ALLOWED; return false; } } return check_docserver($collId); } } /** * Makes all the checks on the docserver and store the file * * @param $catId String Collection identifier * @return Bool true if no error, false otherwise **/ function check_docserver($collId) { $core = new core_tools(); $docserverControler = new docservers_controler(); $storeResult = array(); if (isset($_SESSION['indexing']['path_template']) && !empty($_SESSION['indexing']['path_template']) && isset($_SESSION['indexing']['destination_dir']) && !empty($_SESSION['indexing']['destination_dir']) && isset($_SESSION['indexing']['docserver_id']) && !empty($_SESSION['indexing']['docserver_id']) && isset($_SESSION['indexing']['file_destination_name']) && !empty($_SESSION['indexing']['file_destination_name']) ) { $_SESSION['action_error'] = _CHECK_FORM_OK; return true; } if ($core->is_module_loaded('templates') && $_SESSION['upfile']['format'] == "maarch" ) { if (!isset($_SESSION['template_content']) || empty($_SESSION['template_content']) ) { $_SESSION['action_error'] = _TEMPLATE . ' ' . _IS_EMPTY; return false; } if ( !isset($_SESSION['upfile']['name']) && $_SESSION['upfile']['name'] == '' ) { $_SESSION['upfile']['name'] = 'tmp_file_' . $_SESSION['user']['UserId'] . '_' . rand() . '.maarch'; $tmpPath = $_SESSION['config']['tmppath'] . DIRECTORY_SEPARATOR . $_SESSION['upfile']['name']; $myfile = fopen($tmpPath, "w"); if (!$myfile) { $_SESSION['action_error'] .= _FILE_OPEN_ERROR . '.
'; return false; } fwrite($myfile, $_SESSION['template_content']); fclose($myfile); $_SESSION['upfile']['size'] = filesize($tmpPath); } } if ($_SESSION['origin'] == "scan") { $newFileName = "tmp_file_" . $_SESSION['upfile']['md5'] . '.' . strtolower($_SESSION['upfile']['format']); } else { $newFileName = $_SESSION['upfile']['name']; } $fileInfos = array( "tmpDir" => $_SESSION['config']['tmppath'], "size" => $_SESSION['upfile']['size'], "format" => $_SESSION['upfile']['format'], "tmpFileName" => $newFileName, ); //print_r($fileInfos); $storeResult = $docserverControler->storeResourceOnDocserver($collId, $fileInfos); //print_r($storeResult); if (isset($storeResult['error']) && $storeResult['error'] <> "") { $_SESSION['action_error'] = $storeResult['error']; return false; } else { $_SESSION['indexing']['path_template'] = $storeResult['path_template']; $_SESSION['indexing']['destination_dir'] = $storeResult['destination_dir']; $_SESSION['indexing']['docserver_id'] = $storeResult['docserver_id']; $_SESSION['indexing']['file_destination_name'] = $storeResult['file_destination_name']; $_SESSION['action_error'] = _CHECK_FORM_OK; return true; } } /** * Checks the values of the action form for a given category * * @param $catId String Category identifier * @param $values Array Values of the form to check * @return Bool true if no error, false otherwise **/ function process_category_check($catId, $values) { require_once 'apps' . DIRECTORY_SEPARATOR . $_SESSION['config']['app_id'] . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_types.php'; //print_r($values); $core = new core_tools(); $type = new types(); $db = new Database(); // If No category : Error if (! isset($_ENV['categories'][$catId])) { $_SESSION['action_error'] = _CATEGORY . ' ' . _UNKNOWN . ': ' . $catId; return false; } // Simple cases for ($i = 0; $i < count($values); $i ++) { if (! isset($values[$i]['ID'])) { $tmpId = 'none'; } else { $tmpId = $values[$i]['ID']; } if (isset($_ENV['categories'][$catId][$tmpId]['mandatory']) && $_ENV['categories'][$catId][$tmpId]['mandatory'] == true && empty($values[$i]['VALUE']) ) { $_SESSION['action_error'] = $_ENV['categories'][$catId][$tmpId]['label'] . ' ' . _IS_EMPTY; return false; } if (isset($_ENV['categories'][$catId][$tmpId]['type_form']) && $_ENV['categories'][$catId][$tmpId]['type_form'] == 'date' && ! empty($values[$i]['VALUE']) && preg_match($_ENV['date_pattern'], $values[$i]['VALUE']) == 0 ) { $_SESSION['action_error'] = $_ENV['categories'][$catId][$tmpId]['label'] . ' ' . _WRONG_FORMAT; return false; } if (isset($_ENV['categories'][$catId][$tmpId]['type_form']) && $_ENV['categories'][$catId][$tmpId]['type_form'] == 'integer' && ! empty($values[$i]['VALUE']) && preg_match("/^[0-9]*$/", $values[$i]['VALUE']) == 0 ) { $_SESSION['action_error'] = $_ENV['categories'][$catId][$tmpId]['label'] . ' ' . _WRONG_FORMAT; return false; } if (isset($_ENV['categories'][$catId][$tmpId]['type_form']) && $_ENV['categories'][$catId][$tmpId]['type_form'] == 'radio' && ! empty($values[$i]['VALUE']) && ! in_array( $values[$i]['VALUE'], $_ENV['categories'][$catId][$tmpId]['values'] ) ) { $_SESSION['action_error'] = $_ENV['categories'][$catId][$tmpId]['label'] . ' ' . _WRONG_FORMAT; return false; } } ///// Checks the complementary indexes depending on the doctype $typeId = get_value_fields($values, 'type_id'); $collId = get_value_fields($values, 'coll_id'); $indexes = $type->get_indexes($typeId, $collId, 'minimal'); $valIndexes = array(); for ($i = 0; $i < count($indexes); $i ++) { $valIndexes[$indexes[$i]] = get_value_fields($values, $indexes[$i]); } $testType = $type->check_indexes($typeId, $collId, $valIndexes ); if (! $testType) { $_SESSION['action_error'] .= $_SESSION['error']; $_SESSION['error'] = ''; return false; } ///////////////////////// Other cases // Process limit Date $_SESSION['store_process_limit_date'] = ""; if (isset($_ENV['categories'][$catId]['other_cases']['process_limit_date'])) { $processLimitDateUseYes = get_value_fields( $values, 'process_limit_date_use_yes' ); $processLimitDateUseNo = get_value_fields( $values, 'process_limit_date_use_no' ); if ($processLimitDateUseYes == 'yes') { $_SESSION['store_process_limit_date'] = "ok"; $processLimitDate = get_value_fields($values, 'process_limit_date'); if(trim($processLimitDate) == ""){ $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['process_limit_date']['label'] . " " . _IS_EMPTY; return false; }else if (preg_match($_ENV['date_pattern'], $processLimitDate) == 0 ) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['process_limit_date']['label'] . " " . _WRONG_FORMAT; return false; } } else if ($processLimitDateUseNo == 'no') { $_SESSION['store_process_limit_date'] = "ko"; } $processLimitDate = new datetime($processLimitDate); $processLimitDate = date_add($processLimitDate,date_interval_create_from_date_string('23 hours + 59 minutes + 59 seconds')); } if (isset($_ENV['categories'][$catId]['priority'])) { $priority = get_value_fields( $values, 'priority' ); if ($priority === '') { $_SESSION['action_error'] = $_ENV['categories'][$catId]['priority']['label'] . " " . _MANDATORY; return false; } } // Contact if (isset($_ENV['categories'][$catId]['other_cases']['contact'])) { $contactType = get_value_fields($values, 'type_contact_external'); if (! $contactType) { $contactType = get_value_fields($values, 'type_contact_internal'); } if (! $contactType) { $contactType = get_value_fields($values, 'type_multi_contact_external'); } if (! $contactType) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['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'][$catId]['other_cases']['contact']['label'] . ' ' . _WRONG_FORMAT . ". " . _USE_AUTOCOMPLETION; return false; } if ($_ENV['categories'][$catId]['other_cases']['contact']['mandatory'] == true) { if ((empty($contact) && $contactType != 'multi_external') || ($nb_multi_contact == 0 && $contactType == 'multi_external')) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['contact']['label'] . ' ' . _IS_EMPTY; return false; } } } if ($core->is_module_loaded('entities')) { // Diffusion list if (isset($_ENV['categories'][$catId]['other_cases']['diff_list']) && $_ENV['categories'][$catId]['other_cases']['diff_list']['mandatory'] == true ) { if (empty($_SESSION['indexing']['diff_list']['dest']['users'][0]) || ! isset($_SESSION['indexing']['diff_list']['dest']['users'][0]) ) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['diff_list']['label'] . " " . _MANDATORY; return false; } } } if ($core->is_module_loaded('folder')) { $folderId = ''; $foldertypeId = ''; $folderId = get_value_fields($values, 'folder'); if (isset($_ENV['categories'][$catId]['other_cases']['folder']) && $_ENV['categories'][$catId]['other_cases']['folder']['mandatory'] == true ) { if (empty($folderId)) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['folder']['label'] . ' ' . _IS_EMPTY; return false; } } if (! empty($typeId ) && ! empty($folderId)) { $stmt = $db->query( "SELECT foldertype_id FROM " . FOLD_FOLDERS_TABLE ." WHERE folders_system_id = ?", array($folderId) ); $res = $stmt->fetchObject(); $foldertypeId = $res->foldertype_id; $stmt = $db->query( "SELECT fdl.foldertype_id FROM " . FOLD_FOLDERTYPES_DOCTYPES_LEVEL1_TABLE . " fdl, " . DOCTYPES_TABLE . " d WHERE d.doctypes_first_level_id = " . "fdl.doctypes_first_level_id and fdl.foldertype_id = ? and d.type_id = ?", array($foldertypeId, $typeId) ); if ($stmt->rowCount() == 0) { $_SESSION['action_error'] .= _ERROR_COMPATIBILITY_FOLDER; return false; } } } //For specific case => chrono number $chronoOut = get_value_fields($values, 'chrono_number'); if (isset($_ENV['categories'][$catId]['other_cases']['chrono_number']) && $_ENV['categories'][$catId]['other_cases']['chrono_number']['mandatory'] == true ) { if ($chronoOut == false) { $_SESSION['action_error'] = _NO_CHRONO_NUMBER_DEFINED . ' '; 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; $i < count($values); $i ++) { if ($values[$i]['ID'] == $field) { return $values[$i]['VALUE']; } } return false; } /** * Action of the form : loads the index in the db * * @param $arrId Array Not used here * @param $history String Log the action in history table or not * @param $actionId String Action identifier * @param $label_action String Action label * @param $status String Not used here * @param $collId String Collection identifier * @param $table String Table * @param $formValues String Values of the form to load * @return false or an array * $data['result'] : res_id of the new file followed by # * $data['history_msg'] : Log complement (empty by default) * $data['page_result'] : Page to load when action is done and modal closed **/ function manage_form($arrId, $history, $actionId, $label_action, $status, $collId, $table, $formValues ) { if (empty($formValues) || count($arrId) < 1 || empty($collId)) { $_SESSION['action_error'] = _ERROR_MANAGE_FORM_ARGS; return false; } $db = new Database(); $sec = new security(); $req = new request(); $core = new core_tools(); $resource = new resource(); $type = new types(); $arrayPDO = array(); $_SESSION['data'] = array(); $valIndexes = array(); $resId = ''; $table = $sec->retrieve_table_from_coll($collId); $indColl = $sec->get_ind_collection($collId); $tableExt = $_SESSION['collections'][$indColl]['extensions'][0]; $queryExtFields = '('; $queryExtValues = '('; $_SESSION['origin'] = ""; // Load in the $_SESSION['data'] minimal indexes array_push( $_SESSION['data'], array( 'column' => 'typist', 'value' => $_SESSION['user']['UserId'], 'type' => 'string', ) ); array_push( $_SESSION['data'], array( 'column' => 'docserver_id', 'value' => $_SESSION['indexing']['docserver_id'], 'type' => 'string', ) ); if (isset($_SESSION['upfile']['format'])) { array_push( $_SESSION['data'], array( 'column' => 'format', 'value' => $_SESSION['upfile']['format'], 'type' => 'string', ) ); } $confidentiality_yes = get_value_fields($formValues, 'confidential'); if (!empty($confidentiality_yes)) { array_push( $_SESSION['data'], array( 'column' => 'confidentiality', 'value' => $confidentiality_yes, 'type' => 'string', ) ); } else { $confidentiality_no = get_value_fields($formValues, 'no_confidential'); array_push( $_SESSION['data'], array( 'column' => 'confidentiality', 'value' => $confidentiality_no, 'type' => 'string', ) ); } //store the initiator entity if (isset($_SESSION['user']['primaryentity']['id'])) { array_push( $_SESSION['data'], array( 'column' => 'initiator', 'value' => $_SESSION['user']['primaryentity']['id'], 'type' => 'string', ) ); } $status_id = get_value_fields($formValues, 'status'); if(empty($status_id) || $status_id === "") $status_id = 'BAD'; array_push( $_SESSION['data'], array( 'column' => 'status', 'value' => $status_id, 'type' => 'string', ) ); array_push( $_SESSION['data'], array( 'column' => 'offset_doc', 'value' => '', 'type' => 'string', ) ); array_push( $_SESSION['data'], array( 'column' => 'logical_adr', 'value' => '', 'type' => 'string', ) ); if (isset($_SESSION['origin']) && $_SESSION['origin'] == 'scan') { array_push( $_SESSION['data'], array( 'column' => 'scan_user', 'value' => $_SESSION['user']['UserId'], 'type' => 'string', ) ); array_push( $_SESSION['data'], array( 'column' => 'scan_date', 'value' => $req->current_datetime(), 'type' => 'function', ) ); } //without file case if ( isset($_SESSION['with_file']) && $_SESSION['with_file'] ) { array_push( $_SESSION['data'], array( 'column' => 'source', 'value' => 'with_empty_file', 'type' => 'string', ) ); } $attach = get_value_fields($formValues, 'attach'); $catId = get_value_fields($formValues, 'category_id'); $queryExtFields .= 'category_id,' ; $queryExtValues .= "?," ; $arrayPDO = array_merge($arrayPDO, array($catId)); // Specific indexes : values from the form // Simple cases for ($i = 0; $i < count($formValues); $i ++) { $tmpId = $formValues[$i]['ID']; if (isset($_ENV['categories'][$catId][$tmpId]['type_field']) && $_ENV['categories'][$catId][$tmpId]['type_field'] == 'integer' && $_ENV['categories'][$catId][$tmpId]['table'] <> 'none' ) { if (isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['table'] == 'res' ) { array_push( $_SESSION['data'], array( 'column' => $tmpId, 'value' => $formValues[$i]['VALUE'], 'type' => 'integer', ) ); } else if (isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext' ) { $queryExtFields .= $tmpId . ','; $queryExtValues .= ' ? ,'; $arrayPDO = array_merge($arrayPDO, array($formValues[$i]['VALUE'])); } } else if (isset($_ENV['categories'][$catId][$tmpId]['type_field']) && isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['type_field'] == 'string' && $_ENV['categories'][$catId][$tmpId]['table'] <> 'none' ) { if ($_ENV['categories'][$catId][$tmpId]['table'] == 'res') { array_push( $_SESSION['data'], array( 'column' => $tmpId, 'value' => $formValues[$i]['VALUE'], 'type' => 'string' ) ); } else if ($_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext') { $queryExtFields .= $formValues[$i]['ID'] . ','; $queryExtValues .= " ? ,"; $arrayPDO = array_merge($arrayPDO, array($formValues[$i]['VALUE'])); } } else if (isset($_ENV['categories'][$catId][$tmpId]['type_field']) && isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['type_field'] == 'date' && $_ENV['categories'][$catId][$tmpId]['table'] <> 'none' ) { if ($_ENV['categories'][$catId][$tmpId]['table'] == 'res') { array_push( $_SESSION['data'], array( 'column' => $tmpId, 'value' => functions::format_date_db($formValues[$i]['VALUE']), 'type' => 'date', ) ); } else if ($_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext') { $queryExtFields .= $formValues[$i]['ID'] . ','; $queryExtValues .= " ? ,"; $arrayPDO = array_merge($arrayPDO, array(functions::format_date_db( $formValues[$i]['VALUE'] ))); } } } ///// Manages the complementary indexes depending on the doctype $typeId = get_value_fields($formValues, 'type_id'); $indexes = $type->get_indexes($typeId, $collId, 'minimal'); for ($i = 0; $i < count($indexes); $i ++) { $valIndexes[$indexes[$i]] = get_value_fields( $formValues, $indexes[$i] ); } $_SESSION['data'] = $type->fill_data_array( $typeId, $collId, $valIndexes, $_SESSION['data'] ); ///////////////////////// Other cases // Process limit Date if (isset($_ENV['categories'][$catId]['other_cases']['process_limit_date'])) { $processLimitDate = get_value_fields( $formValues, 'process_limit_date' ); $processLimitDate = new datetime($processLimitDate); $processLimitDate = date_add($processLimitDate,date_interval_create_from_date_string('23 hours + 59 minutes + 59 seconds')); $processLimitDate = (array) $processLimitDate; if ($_ENV['categories'][$catId]['other_cases']['process_limit_date']['table'] == 'res') { array_push( $_SESSION['data'], array( 'column' => 'process_limit_date', 'value' => functions::format_date_db($processLimitDate['date'],'true','','true'), 'type' => 'date', ) ); } else if ($_ENV['categories'][$catId]['other_cases']['process_limit_date']['table'] == 'coll_ext') { if ($_SESSION['store_process_limit_date'] == "ok") { $queryExtFields .= 'process_limit_date,'; $queryExtValues .= " ? ,"; $arrayPDO = array_merge($arrayPDO, array(functions::format_date_db( $processLimitDate['date'],'true','','true' ))); } $_SESSION['store_process_limit_date'] = ""; } } if ($core->is_module_loaded('folder')) { $folderId = ''; $folderId = get_value_fields($formValues, 'folder'); if (! empty($folderId)) { array_push( $_SESSION['data'], array( 'column' => 'folders_system_id', 'value' => $folderId, 'type' => 'integer', ) ); } } if ($core->is_module_loaded('entities')) { // Diffusion list $loadListDiff = false; if (isset($_ENV['categories'][$catId]['other_cases']['diff_list'])) { if (! empty($_SESSION['indexing']['diff_list']['dest']['users'][0]) && isset($_SESSION['indexing']['diff_list']['dest']['users'][0]) ) { array_push( $_SESSION['data'], array( 'column' => 'dest_user', 'value' => $_SESSION['indexing']['diff_list']['dest']['users'][0]['user_id'], 'type' => 'string' ) ); } $loadListDiff = true; } } //print_r($_SESSION['data']); $resId = $resource->load_into_db( $table, $_SESSION['indexing']['destination_dir'], $_SESSION['indexing']['file_destination_name'], $_SESSION['indexing']['path_template'], $_SESSION['indexing']['docserver_id'], $_SESSION['data'], $_SESSION['config']['databasetype'] ); // Contact if (isset($_ENV['categories'][$catId]['other_cases']['contact'])) { $contact = get_value_fields($formValues, 'contact'); $contactType = get_value_fields( $formValues, 'type_contact_external' ); if (! $contactType) { $contactType = get_value_fields( $formValues, 'type_contact_internal' ); } if (! $contactType) { $contactType = get_value_fields( $formValues, 'type_multi_contact_external' ); } $nb_multi_contact = count($_SESSION['adresses']['to']); if($nb_multi_contact > 0 && $contactType == '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($collId, $resId, $_SESSION['adresses']['contactid'][$icontact], $_SESSION['adresses']['addressid'][$icontact])); } $queryExtFields .= 'is_multicontacts,'; $queryExtValues .= "'Y',"; } else { $contactId = get_value_fields($formValues, 'contactid'); if(!ctype_digit($contactId)){ $contactType = 'internal'; }else{ $contactType = 'external'; } if ($contactType == 'internal') { if ($catId == 'incoming' || $catId == 'internal' || $catId == 'ged_doc') { $queryExtFields .= 'exp_user_id,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($contactId)); } else if ($catId == 'outgoing') { $queryExtFields .= 'dest_user_id,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($contactId)); } } else if ($contactType == 'external') { if ($catId == 'incoming' || $catId == 'ged_doc') { $queryExtFields .= 'exp_contact_id,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($contactId)); } else if ($catId == 'outgoing' || $catId == 'internal') { $queryExtFields .= 'dest_contact_id,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($contactId)); } $addressId = get_value_fields($formValues, 'addressid'); $queryExtFields .= 'address_id,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($addressId)); } } } if ($resId <> false) { //Create chrono number //###### $cTypeId = get_value_fields($formValues, 'type_id'); $cEntity = get_value_fields($formValues, 'destination'); $cChronoOut = get_value_fields($formValues, 'chrono_number'); $chronoX = new chrono(); $myVars = array( 'entity_id' => $cEntity, 'type_id' => $cTypeId, 'category_id' => $catId, 'folder_id' => $folderId, ); $_SESSION['folderId'] = $folderId; $myForm = array( 'chrono_out' => $cChronoOut, ); $myChrono = $chronoX->generate_chrono($catId, $myVars, $myForm); $queryExtFields .= 'alt_identifier,'; $queryExtValues .= " ?,"; $arrayPDO = array_merge($arrayPDO, array($myChrono)); //###### $queryExtFields = preg_replace('/,$/', ',res_id)', $queryExtFields); $queryExtValues = preg_replace( '/,$/', ', ?)', $queryExtValues ); $arrayPDO = array_merge($arrayPDO, array($resId)); $queryExt = " INSERT INTO " . $tableExt . " " . $queryExtFields . ' values ' . $queryExtValues ; $db->query($queryExt, $arrayPDO); if ($core->is_module_loaded('folder') && ! empty($folderId) && $_SESSION['history']['folderup'] ) { $hist = new history(); $hist->add( $_SESSION['tablename']['fold_folders'], $folderId, "UP", 'folderup', _DOC_NUM . $resId . _ADDED_TO_FOLDER, $_SESSION['config']['databasetype'], 'apps' ); } if ($core->is_module_loaded('entities')) { if ($loadListDiff) { require_once 'modules' . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_manage_listdiff.php'; $diffList = new diffusion_list(); $params = array( 'mode' => 'listinstance', 'table' => $_SESSION['tablename']['ent_listinstance'], 'coll_id' => $collId, 'res_id' => $resId, 'user_id' => $_SESSION['user']['UserId'], ); $diffList->load_list_db( $_SESSION['indexing']['diff_list'], $params ); } } if ($core->is_module_loaded('tags')) { $tags = get_value_fields($formValues, 'tag_userform'); $tags_list = explode('__', $tags); 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 = ''; $thesaurusList = get_value_fields($formValues, 'thesaurus'); if (! empty($thesaurusList)) { $thesaurus->saveResThesaurusList($thesaurusList,$resId); } } } else { $_SESSION['action_error'] = _ERROR_RES_ID; return false; } if ($attach) { $idDoc = get_value_fields($formValues, 'res_id'); for($i=0;$iquery($queryLink, $arrayPDO); } $hist2 = new history(); $hist2->add($table, $resId, "ADD", 'linkadd', _LINKED_TO . $idDoc, $_SESSION['config']['databasetype'], 'apps' ); $hist3 = new history(); $hist3->add($table, $idDoc, "UP", 'linkup', '(doc. ' . $resId . ')' . _NOW_LINK_WITH_THIS_ONE, $_SESSION['config']['databasetype'], 'apps' ); } if ($core->is_module_loaded('tags')) { include_once("modules" . DIRECTORY_SEPARATOR . "tags" . DIRECTORY_SEPARATOR . "tags_update.php"); } // $_SESSION['indexing'] = array(); unset($_SESSION['upfile']); unset($_SESSION['data']); $_SESSION['action_error'] = _NEW_DOC_ADDED; $_SESSION['indexation'] = true; return array( 'result' => $resId . '#', 'history_msg' => '', 'page_result' => $_SESSION['config']['businessappurl'] . 'index.php?page=details&dir=indexing_searching' . '&coll_id=' . $collId . '&id=' . $resId ); }