. */ /** * @brief Action : indexing a file for the business collection * * 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 Laurent Giovannoni * @date $date$ * @version $Revision$ * @ingroup apps */ //$_SESSION['validStep'] = "ko"; include_once 'apps/' . $_SESSION['config']['app_id'] . '/definition_mail_categories_business.php'; require_once 'core/class/class_security.php'; require_once 'core/core_tables.php'; require_once 'core/class/class_request.php'; require_once 'core/class/class_resource.php'; require_once 'apps/' . $_SESSION['config']['app_id']. '/class/class_business_app_tools.php'; require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_types.php'; require_once 'modules/basket/class/class_modules_tools.php'; require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_indexing_searching_app.php'; require_once 'core/class/docservers_controler.php'; require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_chrono.php'; require_once 'core/class/class_history.php'; $core = new core_tools(); 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'; } if ($core->is_module_loaded('physical_archive')) { require_once 'modules' . DIRECTORY_SEPARATOR . 'physical_archive' . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'class_modules_tools.php'; require_once 'modules/physical_archive/physical_archive_tables.php'; } require_once 'apps/' . $_SESSION['config']['app_id'] . '/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 ) { 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'; } $_SESSION['req'] = "action"; $resId = $values[0]; $frmStr = ''; $type = new types(); $sec = new security(); $b = new basket(); $core = new core_tools(); $business = new business_app_tools(); if ($_SESSION['features']['show_types_tree'] == 'true') { $doctypes = $type->getArrayStructTypes($collId); } else { $doctypes = $type->getArrayTypes($collId); } $today = date('d-m-Y'); $tmp = $business->get_titles(); $titles = $tmp['titles']; $defaultTitle = $tmp['default_title']; if ($core->is_module_loaded('entities')) { $services = array(); $EntitiesIdExclusion = array(); $db = new dbquery(); $db->connect(); # Redirect entities if (count($_SESSION['user']['redirect_groupbasket'][$_SESSION['current_basket']['id']][$actionId]['entities']) > 0) { $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" ); //$db->show(); while ($res = $db->fetch_object()) { array_push($EntitiesIdExclusion, $res->entity_id); } } # Diffusion list types require_once 'modules/entities/class/class_manage_listdiff.php'; $diffList = new diffusion_list(); $groupbasket_difflist_types = $diffList->list_groupbasket_difflist_types( $_SESSION['current_basket']['group_id'], $_SESSION['current_basket']['id'], $actionId ); $difflistTypes = array(); $listmodels = array(); foreach($groupbasket_difflist_types as $difflist_type_id) { $difflistTypes[$difflist_type_id] = $diffList->get_difflist_type($difflist_type_id); $listmodels[$difflist_type_id] = $diffList->select_listmodels($difflist_type_id); } } //var_dump($EntitiesIdExclusion); require_once 'modules/entities/class/class_manage_entities.php'; $ent = new entity(); $allEntitiesTree= array(); $allEntitiesTree = $ent->getShortEntityTreeAdvanced( $allEntitiesTree, 'all', '', $EntitiesIdExclusion, 'all' ); // Select statuses from groupbasket $statuses = array(); $db = new dbquery(); $db->connect(); /* Basket of ABS users */ if($_SESSION['current_basket']['abs_basket']=='1'){ $query="SELECT group_id FROM usergroup_content WHERE user_id='".$_SESSION['current_basket']['basket_owner']."' AND primary_group='Y'"; $db->query($query); $grp_status=$db->fetch_object(); $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= '" . $owner_basket_id . "' and group_id = '" . $owner_usr_grp . "' and action_id = " . $actionId; $db->query($query); if($db->nb_result() > 0) { while($status = $db->fetch_object()) { $statuses[] = array( 'ID' => $status->status_id, 'LABEL' => $db->show_string($status->label_status) ); } } if ($core->is_module_loaded('physical_archive')) { $boxes = array(); $db = new dbquery(); $db->connect(); $db->query( "select arbox_id, title from " . PA_AR_BOXES . " where status = 'NEW' order by title" ); while ($res = $db->fetch_object()) { array_push( $boxes, array( 'ID' => $res->arbox_id, 'LABEL' => $db->show_string($res->title), ) ); } } require_once 'modules/records_management/class/RecordsManagementController.php'; require_once 'core/tests/class/ViewController.php'; $RecordsManagementController = new RecordsManagementController(); $ViewController = new ViewController(); $view = $ViewController->createView(); $folder_select = $view->createSelect(); $folder_select->setAttribute('id', 'schedule'); $folder_select->setAttribute('name', 'schedule'); $folder_select->setAttribute('onChange', 'ArchiveObjectIndexSchedule__select()'); $Schedules = $RecordsManagementController->read( 'Schedule', '100' ); $folder_select->addOption( '', 'Sélectionnez un type d\'archive...' ); makeScheduleList( $Schedules, $folder_select ); $frmStr .= '
'; $frmStr .= ''; $frmStr .= '
'; $frmStr .= ''; /*** Frame to display the doc ***/ $frmStr .= '
'; /*** CAPTURE TOOLBAR ***/ if ( ($core->test_service('scan', 'webtwain', false) === true) || ($core->test_service('photo_capture', 'photo_capture', false) === true) ) { $frmStr .= '
'; $frmStr .= ''; $frmStr .= ''; //Webtwain if ($core->test_service('scan', 'webtwain', false) === true) { $frmStr .= ''; } //Photo capture if ($core->test_service('photo_capture', 'photo_capture', false) === true){ $frmStr .= ''; } //END TOOLBAR $frmStr .= '
'; $frmStr .= ''; $frmStr .= '<<' . '' . _SCAN_DOCUMENT . ''; $frmStr .= ''; $frmStr .= ''; $frmStr .= ''; $frmStr .= '<<' . '' . _PHOTO_CAPTURE . ''; $frmStr .= ''; $frmStr .= '
'; $frmStr .= '
'; } //Webtwain frame if ($core->test_service('scan', 'webtwain', false) === true) { $frmStr .= ''; } //Photo capture frame if ($core->test_service('photo_capture', 'photo_capture', false) === true){ $_SESSION['photofile'] = array(); $frmStr .= ''; } /**** Contact form start *******/ if ($core->test_admin('my_contacts', 'apps', false)) { $frmStr .= ''; } /**** Contact form end *******/ /**** Contact info start *******/ $frmStr .= ''; /**** Contact info end *******/ $frmStr .= ''; //$frmStr .= ''; if ($_SESSION['origin'] == "scan") { $frmStr .= ''; } else { $frmStr .= ''; } $strJs = ''; if ($core->is_module_loaded('webtwain') && isset($_SESSION['user']['services']['scan']) && $_SESSION['user']['services']['scan'] === true ) {//Ajout yck //$frmStr .= ''; $frmStr .= $core->execute_modules_services( $_SESSION['modules_services'], 'index_mlb', 'frame', 'scan', 'webtwain' ); $strJs = 'resize_frame_process(\'modal_' . $actionId . '\', \'scan_iframe\', true, true);'; } $frmStr .= '
'; /*** Extra javascript ***/ $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) { //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) { 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; } $core = new core_tools(); 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 = "tmp_file_" . $_SESSION['user']['UserId'] . '.' // . strtolower($_SESSION['upfile']['format']); $newFileName = $_SESSION['upfile']['name']; } $docserverControler = new docservers_controler(); $fileInfos = array( "tmpDir" => $_SESSION['config']['tmppath'], "size" => $_SESSION['upfile']['size'], "format" => $_SESSION['upfile']['format'], "tmpFileName" => $newFileName, ); //print_r($fileInfos); $storeResult = array(); $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) { $core = new core_tools(); // Simple cases for ($i = 0; $i < count($values); $i ++) { //var_dump($_ENV['categories'][$catId][$tmpId]); 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']) && ! is_numeric($values[$i]['VALUE']) ) { $_SESSION['action_error'] = $_ENV['categories'][$catId][$tmpId]['label'] . ' ' . _WRONG_FORMAT . ' ' . $values[$i]['VALUE']; 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 require_once 'apps/' . $_SESSION['config']['app_id'] . '/class/class_types.php'; $type = new types(); $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) == "" || 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'; } } // Contact if (isset($_ENV['categories'][$catId]['contact_id'])) { $contact = get_value_fields($values, 'contact'); if ($_ENV['categories'][$catId]['contact_id']['mandatory'] == true) { if (empty($contact)) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['contact_id']['label'] . ' ' . _IS_EMPTY; return false; } } // if (!empty($contact)) { // if (preg_match('/\([0-9]+\)$/', $contact) == 0) { // $_SESSION['action_error'] = $_ENV['categories'][$catId]['contact_id']['label'] // . ' ' . _WRONG_FORMAT . '.
'. _USE_AUTOCOMPLETION; // 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']) || ! isset($_SESSION['indexing']['diff_list']) ) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['diff_list']['label'] . " " . _MANDATORY; return false; } } } if ($core->is_module_loaded('folder')) { $db = new dbquery(); $db->connect(); $folderId = ''; $folder = get_value_fields($values, 'folder'); if (isset($_ENV['categories'][$catId]['other_cases']['folder']) && $_ENV['categories'][$catId]['other_cases']['folder']['mandatory'] == true ) { if (empty($folder)) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['folder']['label'] . ' ' . _IS_EMPTY; return false; } } if (! empty($folder)) { if (! preg_match('/\([0-9]+\)$/', $folder)) { $_SESSION['action_error'] = $_ENV['categories'][$catId]['other_cases']['folder']['label'] . " " . _WRONG_FORMAT; return false; } $folderId = str_replace( ')', '', substr($folder, strrpos($folder, '(') + 1) ); $db->query( "select folders_system_id from " . FOLD_FOLDERS_TABLE . " where folders_system_id = " . $folderId ); if ($db->nb_result() == 0) { $_SESSION['action_error'] = _FOLDER . ' ' . $folderId . ' ' . _UNKNOWN; return false; } } if (! empty($typeId ) && ! empty($folderId)) { $foldertypeId = ''; $db->query( "select foldertype_id from " . FOLD_FOLDERS_TABLE ." where folders_system_id = " . $folderId ); $res = $db->fetch_object(); $foldertypeId = $res->foldertype_id; $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 = " . $foldertypeId . " and d.type_id = " . $typeId ); if ($db->nb_result() == 0) { $_SESSION['action_error'] .= _ERROR_COMPATIBILITY_FOLDER; return false; } } } if ($core->is_module_loaded('physical_archive')) { // Arbox id $boxId = get_value_fields($values, 'arbox_id'); if (isset($_ENV['categories'][$catId]['other_cases']['arbox_id']) && $_ENV['categories'][$catId]['other_cases']['arbox_id']['mandatory'] == true ) { if ($boxId == false) { $_SESSION['action_error'] = _NO_BOX_SELECTED . ' '; return false; } } if ($boxId != false && preg_match('/^[0-9]+$/', $boxId)) { $physicalArchive = new physical_archive(); $paReturnValue = $physicalArchive->load_box_db_business( $boxId, $catId, $_SESSION['user']['UserId'] ); if ($paReturnValue == false) { $_SESSION['action_error'] = _ERROR_TO_INDEX_NEW_BATCH_WITH_PHYSICAL_ARCHIVE; 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; } $resId = ''; $db = new dbquery(); $sec = new security(); $req = new request(); $core = new core_tools(); $table = $sec->retrieve_table_from_coll($collId); $indColl = $sec->get_ind_collection($collId); $tableExt = $_SESSION['collections'][$indColl]['extensions'][0]; $queryExtFields = '('; $queryExtValues = '('; $resource = new resource(); $_SESSION['data'] = array(); // 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', ) ); $custom_id = get_value_fields($formValues, 'schedule'); if($custom_id != ''){ array_push( $_SESSION['data'], array( 'column' => 'custom_n1', 'value' => $custom_id, 'type' => 'integer', ) ); } $project_id = get_value_fields($formValues, 'project'); preg_match('#\(+(.*)\)+#', $project_id, $result); if($result[1] != ''){ array_push( $_SESSION['data'], array( 'column' => 'custom_n2', 'value' => $result[1], 'type' => 'integer', ) ); } $arbox_id = get_value_fields($formValues, 'arbox_id'); array_push( $_SESSION['data'], array( 'column' => 'arbox_id', 'value' => $arbox_id, 'type' => 'string', ) ); if (isset($_SESSION['upfile']['format'])) { array_push( $_SESSION['data'], array( 'column' => 'format', 'value' => $_SESSION['upfile']['format'], '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', ) ); } $attach = get_value_fields($formValues, 'attach'); $catId = get_value_fields($formValues, 'category_id'); $queryExtFields .= 'category_id,' ; $queryExtValues .= "'" . $catId . "'," ; $_SESSION['origin'] = ""; // 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 ($formValues[$i]['VALUE'] == '') { $formValues[$i]['VALUE'] = '0'; } if (isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['table'] == 'res' ) { array_push( $_SESSION['data'], array( 'column' => $tmpId, 'value' => str_replace(",", ".", $formValues[$i]['VALUE']), 'type' => 'integer', ) ); } else if (isset($_ENV['categories'][$catId][$tmpId]['table']) && $_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext' ) { $queryExtFields .= $tmpId . ','; $queryExtValues .= str_replace(",", ".", $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' ) { //FIX BUG WITH -- and ; $formValues[$i]['VALUE']=str_replace(';', ' ', $formValues[$i]['VALUE']); $formValues[$i]['VALUE']=str_replace('--', '-', $formValues[$i]['VALUE']); if ($_ENV['categories'][$catId][$tmpId]['table'] == 'res') { array_push( $_SESSION['data'], array( 'column' => $tmpId, 'value' => $db->protect_string_db($formValues[$i]['VALUE']), 'type' => 'string' ) ); } else if ($_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext') { $queryExtFields .= $formValues[$i]['ID'] . ','; $queryExtValues .= "'" . $db->protect_string_db( $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' => $db->format_date_db($formValues[$i]['VALUE']), 'type' => 'date', ) ); } else if ($_ENV['categories'][$catId][$tmpId]['table'] == 'coll_ext') { $queryExtFields .= $formValues[$i]['ID'] . ','; $queryExtValues .= "'" . $db->format_date_db( $formValues[$i]['VALUE'] ) . "',"; } } } ///// Manages the complementary indexes depending on the doctype $type = new types(); $typeId = get_value_fields($formValues, 'type_id'); $indexes = $type->get_indexes($typeId, $collId, 'minimal'); $valIndexes = array(); 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' ); if ($_ENV['categories'][$catId]['other_cases']['process_limit_date']['table'] == 'res') { array_push( $_SESSION['data'], array( 'column' => 'process_limit_date', 'value' => $db->format_date_db($processLimitDate), '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 .= "'" . $db->format_date_db( $processLimitDate ) . "',"; } $_SESSION['store_process_limit_date'] = ""; } } // Contact if (isset($_ENV['categories'][$catId]['contact_id'])) { // $contact = get_value_fields($formValues, 'contact'); //echo 'contact '.$contact.', type '.$contactType; // $contactId = str_replace( // ')', '', substr($contact, strrpos($contact, '(') + 1) // ); $contactId = get_value_fields($formValues, 'contactid'); if ($contactId <> '') { $queryExtFields .= 'contact_id,'; $queryExtValues .= $contactId . ','; $addressId = get_value_fields($formValues, 'addressid'); $queryExtFields .= 'address_id,'; $queryExtValues .= "'" . $db->protect_string_db($addressId) . "',"; } } if ($core->is_module_loaded('folder')) { $folderId = ''; $folder = get_value_fields($formValues, 'folder'); $folderId = str_replace( ')', '', substr($folder, strrpos($folder, '(') + 1) ); if (! empty($folderId)) { array_push( $_SESSION['data'], array( 'column' => 'folders_system_id', 'value' => $folderId, 'type' => 'integer', ) ); } } if ($core->is_module_loaded('physical_archive')) { // Arbox_id + Arbatch_id $boxId = get_value_fields($formValues, 'arbox_id'); if ($boxId <> '') { /*array_push( $_SESSION['data'], array( 'column' => 'arbox_id', 'value' => $boxId, 'type' => 'integer', ) );*/ $physicalArchive = new physical_archive(); $paReturnValue = $physicalArchive->load_box_db_business( $boxId, $catId, $_SESSION['user']['UserId'] ); array_push( $_SESSION['data'], array( 'column' => 'arbatch_id', 'value' => $paReturnValue, 'type' => 'integer', ) ); } } //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'] ); //echo 'load '.$resId. " "; if ($resId <> false) { //###### $queryExtFields = preg_replace('/,$/', ',res_id)', $queryExtFields); $queryExtValues = preg_replace( '/,$/', ',' . $resId . ')', $queryExtValues ); $queryExt = ' insert into ' . $tableExt . ' ' . $queryExtFields . ' values ' . $queryExtValues; $db->connect(); $db->query($queryExt); if ($core->is_module_loaded('folder') && ! empty($folderId) && $_SESSION['history']['folderup'] ) { // echo 'folder '.$resId. " "; $hist = new history(); $hist->add( $_SESSION['tablename']['fold_folders'], $folderId, "UP", 'folderup', _DOC_NUM . $resId . _ADDED_TO_FOLDER, $_SESSION['config']['databasetype'], 'apps' ); } //$db->show(); if ($core->is_module_loaded('entities')) { // echo 'entities '.$resId. " "; $loadListDiff = true; if ($loadListDiff) { require_once 'modules/entities/class/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, 'DOC', $_SESSION['indexing']['diff_list']['object_type'] ); } } if ($core->is_module_loaded('tags')) { include_once('modules/tags/tags_update.php'); } //Photo capture module if ($core->is_module_loaded('photo_capture') && isset($_SESSION['photofile']['name'])) { require_once("modules".DIRECTORY_SEPARATOR."photo_capture" .DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR ."class_modules_tools.php"); $photo_capture = new photo_capture(); $photo_capture->addPhoto($collId, $resId); } } else { $_SESSION['action_error'] = _ERROR_RES_ID; return false; } if ($attach) { $idDoc = get_value_fields($formValues, 'res_id'); $queryLink = "INSERT INTO res_linked (res_parent, res_child, coll_id) VALUES('" . $idDoc . "', '" . $resId . "', '" . $_SESSION['collection_id_choice'] . "')"; $db->connect(); $db->query($queryLink); $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/tags/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_business&dir=indexing_searching' . '&coll_id=' . $collId . '&id=' . $resId ); } function makeScheduleList( $ScheduleTree, $Schedule__select, $level = 0 ) { $subSchedules = $ScheduleTree->Schedule; $l = $subSchedules->length; for($i=0; $i<$l; $i++) { $subSchedule = $subSchedules[$i]; $option = $Schedule__select->addOption( $subSchedule->schedule_id, str_repeat(' ', $level) . $subSchedule->Identifier ); $option->setDataAttribute( 'appraisal_code', $subSchedule->AppraisalCode ); $option->setDataAttribute( 'appraisal_duration', $subSchedule->AppraisalDuration ); $option->setDataAttribute( 'access_restriction_code', $subSchedule->AccessRestrictionCode ); if($level < 1) $option->setStyle('font-variant', 'small-caps'); if($level < 2) $option->setStyle('text-decoration', 'underline'); if($level < 3) $option->setStyle('font-weight', 'bold'); makeScheduleList( $subSchedule, $Schedule__select, $level+1 ); } }