* */ class postindexing extends dbquery { /** * Build Maarch module tables into sessions vars with a xml configuration file */ public function build_modules_tables() { if(file_exists($_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR."modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."config.xml")) { $path = $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR."modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."config.xml"; } else { $path = "modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."config.xml"; } $xmlconfig = simplexml_load_file($path); $PARAMETERS = $xmlconfig->PARAMETERS; unset($_SESSION['postindexing']); $_SESSION['postindexing'] = array(); $_SESSION['postindexing']['max_time'] = (string) $PARAMETERS->max_time; $_SESSION['postindexing']['max_files'] = (string) $PARAMETERS->max_files; $_SESSION['postindexing']['buffer'] = (string) $PARAMETERS->buffer; $_SESSION['postindexing']['status_valid'] = (string) $PARAMETERS->status_valid; $_SESSION['postindexing']['status_reject'] = (string) $PARAMETERS->status_reject; $_SESSION['postindexing']['status_update'] = (string) $PARAMETERS->status_update; } //load the index available by collection public function load_module_var_session() { } //load the index available for postindexing public function get_postindexing_indexes($mode= 'full') { if(file_exists($_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR."modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."index.xml")) { $path = $_SESSION['config']['corepath'].'custom'.DIRECTORY_SEPARATOR.$_SESSION['custom_override_id'].DIRECTORY_SEPARATOR."modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."index.xml"; } else { $path = "modules".DIRECTORY_SEPARATOR."postindexing".DIRECTORY_SEPARATOR."xml".DIRECTORY_SEPARATOR."index.xml"; } $xmlfile = simplexml_load_file($path); $path_lang = 'apps/'.$_SESSION['config']['app_id'].'/lang'.DIRECTORY_SEPARATOR.$_SESSION['config']['lang'].'.php'; $indexes = array(); foreach($xmlfile->INDEX as $item) { if($mode == 'minimal') { array_push($indexes, $item->column ); } else { $tmp = (string) $item->label; //echo $tmp; $tmp2 = $this->retrieve_constant_lang($tmp, $path_lang); if($tmp2 <> false) { $label = $tmp2; } else { $label = $tmp; } $img = (string) $item->img; if(isset($item->default_value) && !empty($item->default_value)) { $tmp = (string) $item->default_value; $tmp2 = $this->retrieve_constant_lang($tmp, $path_lang); if($tmp2 <> false) { $default = $tmp2; } else { $default= $tmp; } } else { $default = false; } if(isset($item->values_list)) { $values = array(); $list = $item->values_list ; foreach($list->value as $val) { $tmp = (string) $val->label; $tmp2 = $this->retrieve_constant_lang($tmp, $path_lang); if($tmp2 <> false) { $label_val = $tmp2; } else { $label_val = $tmp; } array_push($values, array('id' => (string) $val->id, 'label' => $label_val)); } $arr_tmp = array('column' => (string) $item->column, 'label' => $label, 'type' => (string) $item->type, 'img' => $_SESSION['config']['businessappurl'].'static.php?filename='.$img, 'type_field' => 'select', 'values' => $values, 'default_value' => $default, 'mandatory' => (string) $item->mandatory); } else { $arr_tmp = array('column' => (string) $item->column, 'label' => $label, 'type' => (string) $item->type, 'img' => $_SESSION['config']['businessappurl'].'static.php?filename='.$img, 'type_field' => 'input', 'default_value' => $default, 'mandatory' => (string) $item->mandatory); } array_push($indexes, $arr_tmp); } } return $indexes; } public function encrypt_array($str_array) { $hash = ''; if (count($str_array) > 0) { $tmp = ''; foreach ($str_array as $value) { $tmp .= trim($value); } $hash = md5($tmp); } return $hash; } public function get_workbatch () { $this->connect(); // $this->query("select param_value_int from ".$_SESSION['tablename']['param']." where id = 'postindexing_workbatch'"); $line = $this->fetch_object(); $workbatch = (string)$line->param_value_int; $inc_workbatch = $workbatch +1; $this->query("update ".$_SESSION['tablename']['param']." set param_value_int = '".$inc_workbatch."' where id = 'postindexing_workbatch'"); return $workbatch; } public function release_expired_docs($table) { if(!empty($table)) { $timestamp = time(); $this->connect(); $this->query("select distinct res_id from ".$table." where video_batch is not null and video_time < ".$timestamp); //$this->show(); $db = new dbquery(); $db->connect(); while($line = $this->fetch_object()) { $res_id = $line->res_id; $db->query("update ".$table." set video_batch = NULL , video_time = NULL where res_id = ".$res_id); } } } public function release_user_docs($table, $user) { if(!empty($table) && !empty ($user)) { $db = new dbquery(); $db->connect(); $db->query("update ".$table." set video_batch = NULL , video_time = NULL where video_user = '".$user."'"); } } public function get_user_reserved_doc($table) { $tab_resid = array(); if(!empty($table)) { $this->connect(); $this->query("select distinct res_id from ".$table." where video_user = '".$_SESSION['user']['UserId']."'"); while($line = $this->fetch_object()) { $res_id = $line->res_id; if($this->check_reserved_time($res_id, $table)) { $tab_resid[] = $res_id; } } } return $tab_resid; } public function check_reserved_time($res_id, $table) { if(!empty($table) && !empty($res_id)) { $db = new dbquery(); $db->connect(); $db->query("select distinct video_user, video_time from ".$table." where res_id = ".$res_id); //$db->show(); $res = $db->fetch_object(); $timestamp = time(); $maxtime = $res->video_time; $video_user = $res-> video_user; //echo "TIME: ".$timestamp.'/'.$maxtime; if($timestamp > $maxtime) { $db2 = new dbquery(); $db2->connect(); $db2->query("update ".$table." set video_batch = NULL , video_time = NULL where res_id = ".$res_id); return false; } else // Reserved time not yet expired { if($video_user == $_SESSION['user']['UserId'] || empty($video_user)) { return true; } else { return false; } } } else { return false; } } } ?>