*/
require_once("core".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_request.php");
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_types.php");
require_once("modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."class".DIRECTORY_SEPARATOR."class_modules_tools.php");
$core_tools = new core_tools();
$core_tools->load_lang();
$request= new request;
$func = new functions();
$postindexing = new postindexing();
$db = new dbquery();
$type = new types();
$sec = new security();
$coll_id = $_SESSION['tablename']['postindexing_collection'];
$table = $sec->retrieve_table_from_coll($coll_id);
$view = $sec->retrieve_view_from_coll_id($coll_id);
$ind_coll = $sec->get_ind_collection($coll_id);
$table_ext = $_SESSION['collections'][$ind_coll]['extensions'][0];
//*************** CONTROL OF INDEXATION ***************//
$_SESSION['postindexing']['field'] = array();
$_SESSION['data'] = array();
$_SESSION['ext_data'] = array();
$_SESSION['cleanup_data'] = array();
$_SESSION['postindexing']['data'] = array();
$_SESSION['error'] = '';
//On verifie si la session n'a pas expirée sauf dans le cas ou on termine
if (count($postindexing->get_user_reserved_doc($table)) == 0 && !isset($_REQUEST['finish']))
{
$_SESSION['error'] .= _RESERVATION_TIME_EXPIRED.'
';
//Release all the doc of actual user
$postindexing->release_user_docs($table);
//Unlock folder
$postindexing->unlock_current_folder();
//Clear postindexing session values
$postindexing->reinit_postindexing_session();
?>
show_array($_REQUEST); exit;
if(!isset($_REQUEST['finish']))//Only in not finish
{
$indexes = array();
$typeIndexes = array();
$mandatoryIndexes = array();
//Only if not rejected
if (!$_REQUEST['reject'])
{
//****************************The regular field********************************
//Category
if(!isset($_REQUEST['category_id']) || empty($_REQUEST['category_id']))
{
$_SESSION['error'] .= _CATEGORY.' '._IS_EMPTY.'
';
header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=postindexing&page=index_video");
exit;
}
else
{
$cat_id = $_REQUEST['category_id'];
}
//Postindex category fields
foreach(array_keys($_ENV['categories'][$cat_id]) as $field)
{
if ($field <> 'process_limit_date_use' && $field <> 'other_cases' && $field <> 'type_contact' && $field <> 'img_cat')
{
if(empty($_REQUEST[$field]) || strlen(trim($_REQUEST[$field])) == 0 )
{
if($_ENV['categories'][$cat_id][$field]['mandatory'] === true)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id][$field]['label'].' '._IS_EMPTY.'
';
}
}
else
{
if($_ENV['categories'][$cat_id][$field]['type_form'] == 'date' )
{
if(!empty($_REQUEST[$field]) && preg_match($_ENV['date_pattern'],$_REQUEST[$field])== 0)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id][$field]['label'].' '._WRONG_FORMAT.'
';
}
else
{
$value = $func->format_date_db($_REQUEST[$field]);
}
}
elseif($_ENV['categories'][$cat_id][$field]['type_form'] == 'integer')
{
if(!empty($_REQUEST[$field]) && preg_match("/^[0-9]*$/",$_REQUEST[$field])== 0)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id][$field]['label'].' '._WRONG_FORMAT.'
';
}
else
{
$value = $_REQUEST[$field];
}
}
elseif($_ENV['categories'][$cat_id][$field]['type_form'] == 'radio')
{
if(!empty($_REQUEST[$field]) && !in_array($_REQUEST[$field], $_ENV['categories'][$cat_id][$field]['values']))
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id][$field]['label'].' '._WRONG_FORMAT.'
';
}
else
{
$value = $_REQUEST[$field];
}
}
elseif($_ENV['categories'][$cat_id][$field]['type_form'] == 'string')
{
$value = $func->protect_string_db($_REQUEST[$field]);
}
}
//Get the value
if(empty($_SESSION['error']))
{
if ($_ENV['categories'][$cat_id][$field]['table'] == 'res')
{
array_push($_SESSION['data'], array('column' => $field, 'value' => $value, 'type' => $_ENV['categories'][$cat_id][$field]['type_field']));
}
elseif ($_ENV['categories'][$cat_id][$field]['table'] == 'coll_ext')
{
array_push($_SESSION['ext_data'], array('column' => $field, 'value' => $value, 'type' => $_ENV['categories'][$cat_id][$field]['type_field']));
}
}
}
}
/*********** OTHER CASES *******************/
//Contact
if(isset($_ENV['categories'][$cat_id]['other_cases']['contact']))
{
$contact_error = false;
$contact = $_REQUEST['contact'];
$contact_type = $_REQUEST['type_contact'];
if(empty($contact_type))
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['type_contact']['label']." "._MANDATORY.'
';
$contact_error = true;
}
if($_ENV['categories'][$cat_id]['other_cases']['contact']['mandatory'] === true)
{
if(empty($contact))
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['contact']['label'].' '._IS_EMPTY.'
';
$contact_error = true;
}
}
if(!empty($contact))
{
if($contact_type == 'external' && !preg_match('/\(\d+\)$/', trim($contact)))
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['contact']['label']." "._WRONG_FORMAT.".: ".' '._USE_AUTOCOMPLETION.'
';
$contact_error = true;
}
elseif($contact_type == 'internal' && preg_match('/\((.|\s|\d|\h|\w)+\)$/i', $contact) == 0)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['contact']['label']." "._WRONG_FORMAT.".: "._USE_AUTOCOMPLETION.'
';
$contact_error = true;
}
}
//echo 'contact '.$contact.', type '.$contact_type;
if ($contact_error === false)
{
$db->connect();
$db->query("select category_id from " . $view . " where res_id = " . $_SESSION['postindexing']['res_actif']);
$line = $db->fetch_object();
if(isset($line->category_id))
{
$contact_id = str_replace(')', '', substr($contact, strrpos($contact,'(')+1));
if($contact_type == 'internal')
{
if($line->category_id == 'incoming')
{
array_push($_SESSION['ext_data'], array('column' => 'exp_user_id', 'value' => $contact_id, 'type' => "string"));
}
else if($line->category_id == 'outgoing' || $line->category_id == 'internal')
{
array_push($_SESSION['ext_data'], array('column' => 'dest_user_id', 'value' => $contact_id, 'type' => "string"));
}
}
elseif($contact_type == 'external')
{
if($line->category_id == 'incoming')
{
array_push($_SESSION['ext_data'], array('column' => 'exp_contact_id', 'value' => $contact_id, 'type' => "integer"));
}
else if($line->category_id == 'outgoing' || $line->category_id == 'internal')
{
array_push($_SESSION['ext_data'], array('column' => 'dest_contact_id', 'value' => $contact_id, 'type' => "integer"));
}
}
}
}
}
//Physical archive
if($core_tools->is_module_loaded('physical_archive'))
{
if(isset($_ENV['categories'][$cat_id]['other_cases']['arbox_id'] ) && count($_ENV['categories'][$cat_id]['other_cases']['arbox_id']) > 0)
{
if ($_ENV['categories'][$cat_id]['other_cases']['arbox_id']['mandatory'] === true && strlen(trim($_REQUEST['arbox_id'])) == 0)
{
$_SESSION['error'] .= _NO_BOX_SELECTED.'
';
}
else
{
if(preg_match('/^[0-9]+$/', $_REQUEST['arbox_id']))
{
require_once('modules'.DIRECTORY_SEPARATOR.'physical_archive'.DIRECTORY_SEPARATOR.'class'.DIRECTORY_SEPARATOR.'class_modules_tools.php');
$physical_archive = new physical_archive();
$pa_return_value = $physical_archive->load_box_db($_REQUEST['arbox_id'], $cat_id, $_SESSION['user']['UserId']);
if ($pa_return_value == false)
{
$_SESSION['action_error'] = _ERROR_TO_INDEX_NEW_BATCH_WITH_PHYSICAL_ARCHIVE.'
';
//exit;
}
else
{
array_push($_SESSION['data'], array('column' => 'arbox_id', 'value' => $_REQUEST['arbox_id'], 'type' => "integer"));
}
}
else//Is empty arbox, to avoid update error
{
array_push($_SESSION['data'], array('column' => 'arbox_id', 'value' => 'NULL', 'type' => "integer"));
}
}
}
}
//Diffusion list
if($core->is_module_loaded('entities'))
{
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']['user_id']) || !isset($_SESSION['indexing']['diff_list']['dest']['user_id']))
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['diff_list']['label']." "._MANDATORY.'
';
}
}
}
//Project & Market
if($core_tools->is_module_loaded('folder'))
{
$folder_error = false;
$db->connect();
if(isset($_ENV['categories'][$cat_id]['other_cases']['project']) && count($_ENV['categories'][$cat_id]['other_cases']['project']) > 0)
{
if ($_ENV['categories'][$cat_id]['other_cases']['project']['mandatory'] === true && empty($_REQUEST['project']))
{
$_SESSION['error'] .= _PROJECT.' '._IS_EMPTY.'
';
$folder_error = true;
}
else
{
//Get the project Id
$project_id = trim(str_replace(')', '', substr($_REQUEST['project'], strrpos($_REQUEST['project'],'(')+1)));
//If not empty
if (!empty($project_id))
{
if(preg_match("/^[0-9]*$/",$project_id) == 0)
{
$project_id = '';
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['project']['label'].' '._WRONG_FORMAT.'
';
$folder_error = true;
}
else
{
$db->query("select folders_system_id from ".$_SESSION['tablename']['fold_folders']." where folders_system_id = ".$project_id);
if($db->nb_result() == 0)
{
$project_id = '';
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['project']['label'].': '.$project_id.' '._UNKNOWN.'
';
$folder_error = true;
}
}
}
}
}
if(isset($_ENV['categories'][$cat_id]['other_cases']['market'] ) && count($_ENV['categories'][$cat_id]['other_cases']['market']) > 0)
{
if (!empty($_REQUEST['market']))
{
$market_id = str_replace(')', '', substr($_REQUEST['market'], strrpos($_REQUEST['market'],'(')+1));
//If not empty
if (!empty($market_id))
{
if(preg_match("/^[0-9]*$/",$market_id) == 0)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['market']['label'].' '._WRONG_FORMAT.'
';
$folder_error = true;
}
else
{
$db->query("select folders_system_id from ".$_SESSION['tablename']['fold_folders']." where folders_system_id = ".$market_id);
if($db->nb_result() == 0)
{
$_SESSION['error'] .= $_ENV['categories'][$cat_id]['other_cases']['market']['label'].': '.$market_id.' '._UNKNOWN.'
';
$folder_error = true;
}
}
}
}
}
if(!empty($project_id) && !empty($market_id))
{
$db->query("select folders_system_id from ".$_SESSION['tablename']['fold_folders']." where folders_system_id = ".$market_id." and parent_id = ".$project_id);
if($db->nb_result() == 0)
{
$_SESSION['error'] .= _INCOMPATIBILITY_MARKET_PROJECT.'
';
$folder_error = true;
}
}
//Check if the type id belong to the folder
if($folder_error === false && !empty($_REQUEST['type_id']) && (!empty($project_id) || !empty($market_id)))
{
$foldertype_id = '';
if(!empty($market_id))
{
$db->query("select foldertype_id from ".$_SESSION['tablename']['fold_folders']." where folders_system_id = ".$market_id);
$folder_id = $market_id;
}
else //!empty($project_id)
{
$db->query("select foldertype_id from ".$_SESSION['tablename']['fold_folders']." where folders_system_id = ".$project_id);
$folder_id = $project_id;
}
$res = $db->fetch_object();
$foldertype_id = $res->foldertype_id;
$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 = ".$foldertype_id." and d.type_id = ".$_REQUEST['type_id']);
if($db->nb_result() == 0)
{
$_SESSION['error'] .= _ERROR_COMPATIBILITY_FOLDER.'
';
}
else
{
array_push($_SESSION['data'], array('column' => 'folders_system_id', 'value' => $folder_id, 'type' => "integer"));
}
}
}
//************************************************************
//Get the index of the document type
if(!empty($_REQUEST['type_id']))
{
$typeIndexes = $type->get_indexes($_REQUEST['type_id'], $coll_id);
$mandatoryIndexes = $type->get_mandatory_indexes($_REQUEST['type_id'], $coll_id);
if(count($typeIndexes) > 0)
{
foreach(array_keys($typeIndexes) as $ndxKey)
{
if(!empty($_REQUEST[$ndxKey]))
{
if($typeIndexes[$ndxKey]['type'] == 'date')
{
$date_pattern = "/^[0-3][0-9]-[0-1][0-9]-[1-2][0-9][0-9][0-9]$/";
if(preg_match( $date_pattern, $_REQUEST[$ndxKey]) == 0)
{
$_SESSION['error'] .= $typeIndexes[$ndxKey]['label']."
"._WRONG_FORMAT.".
";
}
}
else if($typeIndexes[$ndxKey]['type'] == 'string')
{
$_REQUEST[$ndxKey] = $func->wash($_REQUEST[$ndxKey], "no", $typeIndexes[$ndxKey]['label']);
}
else if($typeIndexes[$ndxKey]['type'] == 'float')
{
$_REQUEST[$ndxKey] = $func->wash($_REQUEST[$ndxKey], "float", $typeIndexes[$ndxKey]['label']);
//Replace comma by point to avoid insert/update error in database
$_REQUEST[$ndxKey] = str_replace(',', '.', $_REQUEST[$ndxKey]);
}
else if($typeIndexes[$ndxKey]['type'] == 'integer')
{
$_REQUEST[$ndxKey] = $func->wash($_REQUEST[$ndxKey], "num", $typeIndexes[$ndxKey]['label']);
}
//Check if values in list exist
if(isset($typeIndexes[$ndxKey]['values']) && count($typeIndexes[$ndxKey]['values']) > 0)
{
$found = false;
for($i=0; $i < count($typeIndexes[$ndxKey]['values']); $i++)
{
if($_REQUEST[$ndxKey] == $typeIndexes[$ndxKey]['values'][$i]['id'])
{
$found = true;
break;
}
}
if(!$found)
{
$_SESSION['error'] .= $typeIndexes[$ndxKey]['label'].": "._ITEM_NOT_IN_LIST.".
";
}
}
//Clean up all index columns before update
array_push($_SESSION['cleanup_data'], array('column' => $ndxKey, 'value' => "", 'type' => 'string'));
//Load data in data array
array_push($_SESSION['data'], array('column' => $ndxKey, 'value' => $func->protect_string_db($_REQUEST[$ndxKey]), 'type' => $typeIndexes[$ndxKey]['type']));
}
else
{
if(in_array($ndxKey, $mandatoryIndexes))
{
$_SESSION['error'] .= $typeIndexes[$ndxKey]['label']." "._MANDATORY.".
";
}
}
}
}
}
else
{
//$_SESSION['error'] .= _PIECE_TYPE." "._MANDATORY.".
";
}
}
//Debug request and data array
//$func->show_array($_REQUEST); $func->show_array($_SESSION['data']); echo 'Error: '.$_SESSION['error']; exit;
//Lets treat!
if(!empty($_SESSION['error']) && !isset($_REQUEST['reject']))
{
header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=postindexing&page=index_video");
}
else
{
//If valid data
if (isset($_REQUEST['valid']))
{
$lib_action = _VIDEO_UPDATED;
array_push($_SESSION['data'], array('column' => 'status', 'value' => $func->protect_string_db($_SESSION['postindexing']['status_update']), 'type' => 'string'));
}
elseif(isset($_REQUEST['reject'])) //If reject
{
//Reinitialiser le tableau pour ne mettre à jour que le status
$_SESSION['data'] = array();
//Vu qu'on ne gere pas les erreurs en cas de rejet
$_SESSION['error'] = '';
$lib_action = _VIDEO_REJECTED;
array_push($_SESSION['data'], array('column' => 'status', 'value' => $func->protect_string_db($_SESSION['postindexing']['status_reject']), 'type' => 'string'));
}
//Mettre à jour les infos
if (count($_SESSION['data']) > 0)
{
//where
$where = "res_id = ".$_SESSION['postindexing']['res_actif'];
//Cleanup doctype index before update
if (count($_SESSION['cleanup_data']) >0 )
{
$request->update($table, $_SESSION['cleanup_data'], $where, $_SESSION['config']['databasetype']);
//$request->show();
}
//Add postindexinf=g info
array_push($_SESSION['data'], array('column' => "video_date", 'value' => $request->current_datetime(), 'type' => "function"));
//$func->show_array($_SESSION['data']);exit;
//Update doc
$request->update($table, $_SESSION['data'], $where, $_SESSION['config']['databasetype']);
//$request->show(); exit;
//Update extension table
if (count($_SESSION['ext_data']) >0 )
{
$request->update($table_ext, $_SESSION['ext_data'], $where, $_SESSION['config']['databasetype']);
//$request->show();
}
//History
if($_SESSION['history']['resup'] == "true")
{
require_once("core/class/class_history.php");
$hist = new history();
$hist->add($table, $_SESSION['postindexing']['res_actif'], "UP", _INDEX_UPDATED." (".strtolower(_NUM).$_SESSION['postindexing']['res_actif']."".$lib_action.")", $_SESSION['config']['databasetype'],'postindexing');
}
}
//Update work number
if(count($_SESSION['postindexing']['docs']) > $_SESSION['postindexing']['work'])
{
$_SESSION['postindexing']['work'] = $_SESSION['postindexing']['work'] + 1;
}
//Debug pour l'affichage du nombre de documents validés
//$_SESSION['info'] = $_SESSION['postindexing']['work'].'/'.count($_SESSION['postindexing']['docs']);
//Nexxxxttttt!!!!!!
if (count($_SESSION['postindexing']['docs']) == $_SESSION['postindexing']['work'])//Si on est arrivé a la fin des documents
{
//On revient au début
$_SESSION['postindexing']['resid_pointeur'] = 0;
//On reinitialise le nombre de documents validés
//$_SESSION['postindexing']['work'] = 0;
//Un petit message
$_SESSION['info'] .= _VIDEO_RES_FINISH;
}
else
{
//On repasse au document suivant
$_SESSION['postindexing']['resid_pointeur'] = $_SESSION['postindexing']['resid_pointeur'] + 1;
}
header("location: ".$_SESSION['config']['businessappurl']."index.php?display=true&module=postindexing&page=index_video");
}
}
elseif(isset($_REQUEST['finish']))
{
//Release all the doc of actual user
$postindexing->release_user_docs($table);
//Si on est en mode folder
if (isset($_SESSION['postindexing']['folder_system_id']) && !empty($_SESSION['postindexing']['folder_system_id']))
{
if (count($_SESSION['postindexing']['docs']) == $_SESSION['postindexing']['work']) //Si on a vidéocodé tous les documents
{
$postindexing->update_status_folder($_SESSION['postindexing']['folder_system_id'], $_SESSION['postindexing']['folder_status_update']);
}
//Unlock folder
$postindexing->unlock_current_folder();
}
?>