function explnum_add_from_url($f_notice_id, $f_bulletin_id, $f_nom, $f_url, $overwrite = true, $source_id = 0, $filename = '', $f_path = '', $f_statut) { global $dbh, $base_path; if ($f_bulletin_id) { $f_notice_id = 0; } else { if (!$f_bulletin_id && $f_notice_id) { $f_bulletin_id = 0; } } if (!$overwrite) { $sql_find = "SELECT count(*) FROM explnum WHERE explnum_notice = " . $f_notice_id . " AND explnum_nom = '" . addslashes($f_nom) . "'"; $res = pmb_mysql_query($sql_find, $dbh); $count = pmb_mysql_result($res, 0, 0); if ($count) { return; } } $sql_delete = "DELETE FROM explnum WHERE explnum_notice = " . $f_notice_id . " AND explnum_nom = '" . addslashes($f_nom) . "' "; pmb_mysql_query($sql_delete, $dbh); $original_filename = basename($f_url); $extension = substr($original_filename, strripos($original_filename, '.') * 1 + 1); $tmp_filename = explnum::static_rename($extension); if ($filename) { $new_filename = $filename; } else { $new_filename = $tmp_filename; } //copie en répertoire temporaire $r = false; if (file_exists($f_url) && filesize($f_url)) { //document en repertoire $r = copy($f_url, $base_path . '/temp/' . $tmp_filename); } else { //url $aCurl = new Curl(); $content = $aCurl->get($f_url); $content = $content->body; $r = file_put_contents("{$base_path}/temp/" . $tmp_filename, $content); } if ($r) { //construction vignette $vignette = construire_vignette('', $tmp_filename); create_tableau_mimetype(); $mimetype = trouve_mimetype("{$base_path}/temp/" . $tmp_filename, $extension); //si la source du connecteur est précisée, on regarde si on a pas un répertoire associé $rep_upload = 0; if ($source_id) { $check_rep = "select rep_upload from connectors_sources where source_id = " . $source_id; $res = pmb_mysql_query($check_rep); if (pmb_mysql_num_rows($res)) { $rep_upload = pmb_mysql_result($res, 0, 0); } } if ($rep_upload != 0) { $upload_folder = new upload_folder($rep_upload); $rep_path = $upload_folder->get_path($new_filename); if ($f_path && file_exists($rep_path . $f_path)) { $rep_path = $rep_path . $f_path . '/'; } if (file_exists($upload_folder->encoder_chaine($rep_path . $new_filename))) { $suffix = 1; $ext = extension_fichier($new_filename); $file = str_replace("." . $ext, "", basename($new_filename)); while (file_exists($upload_folder->encoder_chaine($rep_path . $file . "_" . $suffix . "." . $ext))) { $suffix++; } $new_filename = $file . "_" . $suffix . "." . $ext; } rename("{$base_path}/temp/" . $tmp_filename, $upload_folder->encoder_chaine($rep_path . $new_filename)); $path = $upload_folder->formate_path_to_save($upload_folder->formate_path_to_nom($rep_path)); $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_bulletin, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_vignette, explnum_repertoire, explnum_path, explnum_docnum_statut) VALUES ("; $insert_sql .= $f_notice_id . ","; $insert_sql .= $f_bulletin_id . ","; $insert_sql .= "'" . addslashes($f_nom) . "',"; $insert_sql .= "'" . addslashes($new_filename) . "',"; $insert_sql .= "'" . addslashes($mimetype) . "',"; $insert_sql .= "'" . addslashes($extension) . "',"; $insert_sql .= "'" . addslashes($vignette) . "',"; $insert_sql .= "'" . addslashes($rep_upload) . "',"; $insert_sql .= "'" . addslashes($path) . "',"; $insert_sql .= $f_statut; $insert_sql .= ")"; } else { $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_bulletin, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_data, explnum_vignette, explnum_docnum_statut) VALUES ("; $insert_sql .= $f_notice_id . ","; $insert_sql .= $f_bulletin_id . ","; $insert_sql .= "'" . addslashes($f_nom) . "',"; $insert_sql .= "'" . addslashes($new_filename) . "',"; $insert_sql .= "'" . addslashes($mimetype) . "',"; $insert_sql .= "'" . addslashes($extension) . "',"; $insert_sql .= "'" . addslashes($content) . "',"; $insert_sql .= "'" . addslashes($vignette) . "',"; $insert_sql .= $f_statut; $insert_sql .= ")"; } if (pmb_mysql_query($insert_sql, $dbh)) { $docnum_id = pmb_mysql_insert_id($dbh); if ($docnum_id) { $index = new indexation_docnum($docnum_id); $index->indexer(); } } /* $aCurl = new Curl(); $content = $aCurl->get($f_url); $content = $content->body; $origine=str_replace(" ","",microtime()); $origine=str_replace("0.","",$origine); $original_filename = basename($f_url); if( $filename != "") $afilename = $filename; else $afilename = $origine.$original_filename; if (!$original_filename) $original_filename = $afilename; file_put_contents("$base_path/temp/".$afilename, $content); */ /* $vignette = construire_vignette('', $afilename); create_tableau_mimetype(); $afilename_ext=extension_fichier($afilename); $mimetype = trouve_mimetype("$base_path/temp/".$afilename, $afilename_ext); $extension = strrchr($afilename, '.'); //si la source du connecteur est précisée, on regarde si on a pas un répertoire associé if ($source_id){ $check_rep = "select rep_upload from connectors_sources where source_id = ".$source_id; $res = pmb_mysql_query($check_rep); if(pmb_mysql_num_rows($res)){ $rep_upload = pmb_mysql_result($res,0,0); } } */ /* if($rep_upload != 0){ $upload_folder = new upload_folder($rep_upload); $rep_path = $upload_folder->get_path($afilename); if ($f_path && file_exists($rep_path.$f_path)) { $rep_path=$rep_path.$f_path.'/'; } copy("$base_path/temp/".$afilename,$rep_path.$afilename); $path =$upload_folder->formate_path_to_save($upload_folder->formate_path_to_nom($rep_path)); $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_vignette, explnum_repertoire, explnum_path) VALUES ("; $insert_sql .= $f_notice_id.","; $insert_sql .= "'".addslashes($f_nom)."',"; $insert_sql .= "'".addslashes($afilename)."',"; $insert_sql .= "'".addslashes($mimetype)."',"; $insert_sql .= "'".addslashes($extension)."',"; $insert_sql .= "'".addslashes($vignette)."',"; $insert_sql .= "'".addslashes($rep_upload)."',"; $insert_sql .= "'".addslashes($path)."'"; $insert_sql .= ")"; }else{ $insert_sql = "INSERT INTO explnum (explnum_notice, explnum_nom, explnum_nomfichier, explnum_mimetype, explnum_extfichier, explnum_data, explnum_vignette) VALUES ("; $insert_sql .= $f_notice_id.","; $insert_sql .= "'".addslashes($f_nom)."',"; $insert_sql .= "'".addslashes($afilename)."',"; $insert_sql .= "'".addslashes($mimetype)."',"; $insert_sql .= "'".addslashes($extension)."',"; $insert_sql .= "'".addslashes($content)."',"; $insert_sql .= "'".addslashes($vignette)."'"; $insert_sql .= ")"; } pmb_mysql_query($insert_sql, $dbh); unlink("$base_path/temp/".$afilename); */ } }
function save_property_form($planificateur_id) { global $dbh, $type_task_id, $charset; global $task_name, $task_desc, $form_users, $task_active; global $id_rep, $path; global $task_perio_heure, $task_perio_min, $chkbx_task_quotidien, $chkbx_task_hebdo, $chkbx_task_mensuel; $params = $this->make_serialized_task_params(); $task_perio_heure = $task_perio_heure == '' ? '*' : $task_perio_heure; $task_perio_minute = $task_perio_min == '' ? '*' : $task_perio_min; //concaténation de la periodicité des jours du mois $task_perio_quotidien = ""; if ($chkbx_task_quotidien[0] == '*') { $task_perio_quotidien .= $chkbx_task_quotidien[0] . ","; } else { for ($i = 0; $i < sizeof($chkbx_task_quotidien); $i++) { $task_perio_quotidien .= $chkbx_task_quotidien[$i] . ","; } } $task_perio_quotidien = $task_perio_quotidien != '' ? substr($task_perio_quotidien, 0, strlen($task_perio_quotidien) - 1) : '*'; //concaténation de la periodicité des jours de la semaine $task_perio_hebdo = ""; if ($chkbx_task_hebdo[0] == '*') { $task_perio_hebdo .= $chkbx_task_hebdo[0] . ","; } else { for ($i = 0; $i < sizeof($chkbx_task_hebdo); $i++) { $task_perio_hebdo .= $chkbx_task_hebdo[$i] . ","; } } $task_perio_hebdo = $task_perio_hebdo != '' ? substr($task_perio_hebdo, 0, strlen($task_perio_hebdo) - 1) : '*'; //concaténation de la periodicité des mois $task_perio_mensuel = ""; if ($chkbx_task_mensuel[0] == '*') { $task_perio_mensuel .= $chkbx_task_mensuel[0] . ","; } else { for ($i = 0; $i < sizeof($chkbx_task_mensuel); $i++) { $task_perio_mensuel .= $chkbx_task_mensuel[$i] . ","; } } $task_perio_mensuel = $task_perio_mensuel != '' ? substr($task_perio_mensuel, 0, strlen($task_perio_mensuel) - 1) : '*'; if ($id_rep && $path) { $up = new upload_folder($id_rep); $path = stripslashes($path); $path_name = $up->formate_path_to_save($up->formate_path_to_nom($path)); } else { $id_rep = ""; $path_name = ""; } // est-ce une nouvelle tâche ?? if ($planificateur_id == '') { //Nouvelle planification $requete = "insert into planificateur (num_type_tache, libelle_tache, desc_tache, num_user, param, statut, rep_upload, path_upload, perio_heure, \n\t\t\t\tperio_minute, perio_jour_mois, perio_jour, perio_mois) \n\t\t\t\tvalues(" . $type_task_id . ",'" . addslashes($task_name) . "','" . addslashes($task_desc) . "',\n\t\t\t\t'" . $form_users . "','" . $params . "','" . $task_active . "','" . $id_rep . "','" . $path_name . "','" . $task_perio_heure . "','" . $task_perio_minute . "',\n\t\t\t\t'" . htmlentities($task_perio_quotidien, ENT_QUOTES, $charset) . "','" . htmlentities($task_perio_hebdo, ENT_QUOTES, $charset) . "','" . htmlentities($task_perio_mensuel, ENT_QUOTES, $charset) . "')"; mysql_query($requete, $dbh); $planificateur_id = mysql_insert_id(); } else { //Mise à jour des informations $requete = "update planificateur\n\t\t\t\tset num_type_tache = '" . $type_task_id . "',\n\t\t\t\tlibelle_tache = '" . addslashes($task_name) . "',\n\t\t\t\tdesc_tache = '" . addslashes($task_desc) . "',\n\t\t\t\tnum_user = '******',\n\t\t\t\tparam = '" . $params . "',\n\t\t\t\tstatut = '" . $task_active . "',\n\t\t\t\trep_upload = '" . $id_rep . "',\n\t\t\t\tpath_upload = '" . $path_name . "',\n\t\t\t\tperio_heure = '" . $task_perio_heure . "', \n\t\t\t\tperio_minute = '" . $task_perio_minute . "',\n\t\t\t\tperio_jour_mois = '" . htmlentities($task_perio_quotidien, ENT_QUOTES, $charset) . "',\n\t\t\t\tperio_jour = '" . htmlentities($task_perio_hebdo, ENT_QUOTES, $charset) . "',\n\t\t\t\tperio_mois = '" . htmlentities($task_perio_mensuel, ENT_QUOTES, $charset) . "'\n\t\t\t\twhere id_planificateur='" . $planificateur_id . "'"; mysql_query($requete, $dbh); } //calcul de la prochaine exécution $this->calcul_execution($planificateur_id); //Vérification des paramètres enregistrés $this->checkParams($planificateur_id); // insertion d'une nouvelle tâche si aucune n'est planifiée $this->insertOfTask($planificateur_id, $task_active); }
function get_file_from_temp($filename, $name, $upload_place) { global $base_path; global $ck_index; global $id_rep, $up_place; $up_place = $upload_place; create_tableau_mimetype(); $ck_index = true; //Initialisation des tableaux d'infos $this->infos_docnum = $this->params = array(); $this->infos_docnum["mime"] = trouve_mimetype($filename, extension_fichier($name)); $this->infos_docnum["nom"] = substr($name, 0, strrpos($name, ".")); if (!$this->infos_docnum["nom"]) { $this->infos_docnum["nom"] = $name; } $this->infos_docnum["notice"] = $this->explnum_notice; $this->infos_docnum["bull"] = $this->explnum_bulletin; $this->infos_docnum["url"] = ""; $this->infos_docnum["fic"] = false; $this->infos_docnum["contenu_vignette"] = construire_vignette('', substr($filename, strrpos($filename, "/"))); $this->infos_docnum["userfile_name"] = $name; $this->infos_docnum["userfile_ext"] = extension_fichier($name); if ($up_place && $id_rep != 0) { $upfolder = new upload_folder($id_rep); $chemin_hasher = "/"; if ($upfolder->isHashing()) { $rep = $upfolder->hachage($this->infos_docnum["userfile_name"]); @mkdir($rep); $chemin_hasher = $upfolder->formate_path_to_nom($rep); $file_name = $rep . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save($chemin_hasher); } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; $chemin = $upfolder->formate_path_to_save("/"); } $this->infos_docnum["path"] = $chemin; $file_name = $upfolder->encoder_chaine($file_name); if (!$this->explnum_nomfichier) { //Si je suis en création de fichier numérique $nom_tmp = $this->infos_docnum["userfile_name"]; $continue = true; $compte = 1; do { $query = "select explnum_notice,explnum_id from explnum where explnum_nomfichier = '" . addslashes($nom_tmp) . "' AND explnum_repertoire='" . $id_rep . "' AND explnum_path='" . addslashes($this->infos_docnum["path"]) . "'"; $result = mysql_query($query); if (mysql_num_rows($result) && mysql_result($result, 0, 0) != $this->infos_docnum["notice"]) { //Si j'ai déjà un document numérique avec ce fichier pour une autre notice je dois le renommer pour ne pas perdre l'ancien if (preg_match("/^(.+)(\\..+)\$/i", $this->infos_docnum["userfile_name"], $matches)) { $nom_tmp = $matches[1] . "_" . $compte . $matches[2]; } else { $nom_tmp = $this->infos_docnum["userfile_name"] . "_" . $compte; } $compte++; } else { if (mysql_num_rows($result)) { //J'ai déjà ce fichier pour cette notice //Je dois enlever l'ancien document numérique pour ne pas l'avoir en double $old_docnum = new explnum(mysql_result($result, 0, 1)); $old_docnum->delete(); } else { } $continue = false; } } while ($continue); if ($compte != 1) { $this->infos_docnum["userfile_name"] = $nom_tmp; if ($upfolder->isHashing()) { $file_name = $rep . $this->infos_docnum["userfile_name"]; } else { $file_name = $upfolder->get_path($this->infos_docnum["userfile_name"]) . $this->infos_docnum["userfile_name"]; } $file_name = $upfolder->encoder_chaine($file_name); } else { } } else { } rename($filename, $file_name); } else { //enregistrement en base $this->infos_docnum["contenu"] = file_get_contents($filename); } $this->params["maj_mimetype"] = true; $this->params["maj_data"] = true; $this->params["maj_vignette"] = true; }