name = '';
$this->comment = '';
$this->nb_item = 0;
$this->nb_item_pointe = 0;
$this->autorisations = "";
$this->autorisations_all = 0;
$this->classementGen = "";
$this->acces_rapide = 0;
$this->favorite_color = '';
$this->creation_user_name = '';
$this->creation_date = '0000-00-00 00:00:00';
}
protected function get_template_form() {
return "";
}
protected function get_warning_delete() {
}
protected function get_type_form() {
global $msg;
global $current_print;
if ($this->get_idcaddie() && $this->nb_item) {
$type = "caddie_de_".$this->type;
return $msg[$type];
} else {
$select_cart="
";
return $select_cart;
}
}
// formulaire
public function get_form($form_action="", $form_cancel="", $form_duplicate="") {
global $msg, $charset;
global $PMBuserid;
global $current_print;
global $clause, $filtered_query;
$form = $this->get_template_form();
$form = str_replace ( '!!formulaire_action!!', $form_action, $form );
$form = str_replace('!!formulaire_annuler!!', $form_cancel, $form);
if ($this->get_idcaddie()) {
$form = str_replace ( '!!title!!', $msg['edit_cart'], $form);
$form = str_replace('!!autorisations_users!!', users::get_form_autorisations($this->autorisations,0), $form);
$form = str_replace('!!infos_creation!!', "
".$this->get_info_creation(), $form);
$button_duplicate = " ";
$form = str_replace('!!button_duplicate!!', $button_duplicate, $form);
} else {
$form = str_replace ( '!!title!!', $msg['new_cart'], $form);
$form = str_replace('!!autorisations_users!!', users::get_form_autorisations("",1), $form);
$form = str_replace('!!infos_creation!!', "", $form);
$form = str_replace('!!button_duplicate!!', "", $form);
}
$form = str_replace('!!name!!', htmlentities($this->name,ENT_QUOTES, $charset), $form);
$form = str_replace('!!comment!!', htmlentities($this->comment,ENT_QUOTES, $charset), $form);
$form = str_replace('!!autorisations_all!!', ($this->autorisations_all ? "checked='checked'" : ""), $form);
$classementGen = new classementGen(static::get_table_name(), $this->get_idcaddie());
$form = str_replace("!!object_type!!",$classementGen->object_type,$form);
$form = str_replace("!!classements_liste!!",$classementGen->getClassementsSelectorContent($PMBuserid,$classementGen->libelle),$form);
$form = str_replace("!!acces_rapide!!",($this->acces_rapide?"checked='checked'":""),$form);
$form = str_replace("!!favorite_color!!", $this->favorite_color,$form);
$memo_contexte = "";
if($clause) {
$memo_contexte .= "";
}
if($filtered_query) {
$memo_contexte.="";
}
$form=str_replace('', $memo_contexte, $form);
return $form;
}
protected function get_links_form() {
return "";
}
public function set_properties_from_form() {
global $autorisations;
global $autorisations_all;
global $cart_name;
global $cart_comment;
global $acces_rapide;
global $favorite_color;
if (is_array($autorisations)) {
$this->autorisations=implode(" ",$autorisations);
} else {
$this->autorisations="1";
}
$this->autorisations_all = $autorisations_all+0;
$this->name = stripslashes($cart_name);
$this->comment = stripslashes($cart_comment);
$this->acces_rapide = (isset($acces_rapide)?1:0);
$this->favorite_color = $favorite_color;
}
protected static function get_order_cart_list() {
return " order by name, comment ";
}
public static function get_cart_data($temp) {
return array();
}
public static function get_query_cart_list($restriction_panier="",$acces_rapide = 0,$item = 0, $with_order = true) {
global $PMBuserid;
$query = "SELECT * FROM ".static::get_table_name();
if($item) {
$query .= " JOIN ".static::get_table_content_name()." ON ".static::get_table_content_name().".".static::get_field_content_name()." = ".static::get_table_name().".".static::get_field_name()." AND ".static::get_table_content_name().".object_id = ".$item;
}
if ($restriction_panier=="" || (static::class == 'empr_caddie')) {
$query .= " where 1 ";
} else {
$query .= " where type='$restriction_panier' ";
}
if ($PMBuserid!=1) {
$query.=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid' or autorisations_all=1) ";
}
if ($acces_rapide) {
$query .= " and acces_rapide=1";
}
if($with_order) {
$query .= static::get_order_cart_list();
}
return $query;
}
static public function get_query_filters() {
global $elt_flag, $elt_no_flag;
$filter_query = '';
if ($elt_flag && $elt_no_flag ) $filter_query .= "";
if (!$elt_flag && $elt_no_flag ) $filter_query .= " and flag is null ";
if ($elt_flag && !$elt_no_flag ) $filter_query .= " and flag is not null ";
return $filter_query;
}
// liste des paniers disponibles
public static function get_cart_list($restriction_panier="",$acces_rapide = 0) {
$cart_list=array();
$query = static::get_query_cart_list($restriction_panier, $acces_rapide);
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)) {
while ($temp = pmb_mysql_fetch_object($result)) {
$cart_list[] = static::get_cart_data($temp);
}
}
return $cart_list;
}
// liste des paniers dans lesquels est présent l'item
public static function get_cart_list_from_item($restriction_panier="",$acces_rapide = 0, $item = 0) {
$cart_list=array();
$query = static::get_query_cart_list($restriction_panier, $acces_rapide, $item);
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)) {
while ($temp = pmb_mysql_fetch_object($result)) {
$cart_list[] = static::get_cart_data($temp);
}
}
return $cart_list;
}
public static function get_cart_list_selector($restriction_panier="", $name="", $selected=0) {
global $msg, $PMBuserid;
$query = "SELECT ".static::get_field_name().", name, caddie_classement FROM ".static::get_table_name()." where type='".$restriction_panier."' ";
if ($PMBuserid!=1) $query.=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') ";
$query.=" ORDER BY caddie_classement, name ";
return gen_liste ($query, static::get_field_name(), "name", $name, "", $selected, 0, $msg['dsi_panier_aucun'], 0,$msg['dsi_panier_aucun'], 0, '', 'caddie_classement');
}
public static function get_cart_list_multiple_selector($restriction_panier="", $name="", $selected=array()) {
global $msg, $PMBuserid;
$query = "SELECT ".static::get_field_name().", name, caddie_classement FROM ".static::get_table_name()." where type='".$restriction_panier."' ";
if ($PMBuserid!=1) $query.=" and (autorisations='$PMBuserid' or autorisations like '$PMBuserid %' or autorisations like '% $PMBuserid %' or autorisations like '% $PMBuserid') ";
$query.=" ORDER BY caddie_classement, name ";
return gen_liste_multiple ($query, static::get_field_name(), "name", "", $name, "", $selected, 0, $msg['dsi_panier_aucun'], 0,'', 10, 'caddie_classement');
}
protected function get_info_user() {
global $PMBuserid;
$query = "SELECT CONCAT(prenom, ' ', nom) as name FROM users WHERE userid=".$PMBuserid;
$result = pmb_mysql_query($query);
if (pmb_mysql_num_rows($result)) {
return pmb_mysql_fetch_object($result);
}
return false;
}
// l'item est-il dans le panier ?
public static function has_item($idcaddie=0, $item=0) {
$query = "select count(*) FROM ".static::get_table_content_name()." where ".static::get_field_content_name()."='".$idcaddie."' and object_id='".$item."' ";
$result = pmb_mysql_query($query);
return pmb_mysql_result($result, 0, 0);
}
// suppression d'un item
public function del_item($item=0) {
$query = "delete FROM ".static::get_table_content_name()." where ".static::get_field_content_name()."='".$this->get_idcaddie()."' and object_id='".$item."' ";
$result = @pmb_mysql_query($query);
$this->compte_items();
}
// Dépointage de tous les items
public function depointe_items() {
$query = "update ".static::get_table_content_name()." set flag=null where ".static::get_field_content_name()."='".$this->get_idcaddie()."' ";
$result = @pmb_mysql_query($query);
$this->compte_items();
}
// Dépointage d'un item
public function depointe_item($item=0) {
if ($item) {
$query = "update ".static::get_table_content_name()." set flag=null where ".static::get_field_content_name()."='".$this->get_idcaddie()."' and object_id='".$item."' ";
$result = @pmb_mysql_query($query);
if ($result) {
$this->compte_items();
return 1;
} else {
return 0;
}
}
}
public function pointe_items_from_query($query) {
global $msg;
if (pmb_strtolower(pmb_substr($query,0,6))!="select") {
error_message_history($msg['caddie_action_invalid_query'],$msg['requete_echouee'],1);
exit();
}
$result_selection = pmb_mysql_query($query);
if (!$result_selection) {
error_message_history($msg['caddie_action_invalid_query'],$msg['requete_echouee'].pmb_mysql_error(),1);
exit();
}
if(pmb_mysql_num_rows($result_selection)) {
while ($obj_selection = pmb_mysql_fetch_object($result_selection)) {
if(static::class == 'empr_caddie') {
$this->pointe_item($obj_selection->object_id);
} else {
$this->pointe_item($obj_selection->object_id,$obj_selection->object_type);
}
}
}
}
// suppression d'un panier
public function delete() {
$query = "delete FROM ".static::get_table_content_name()." where ".static::get_field_content_name()."='".$this->get_idcaddie()."' ";
$result = pmb_mysql_query($query);
$query = "delete FROM ".static::get_table_name()." where ".static::get_field_name()."='".$this->get_idcaddie()."' ";
$result = pmb_mysql_query($query);
}
// compte_items
public function compte_items() {
$this->nb_item = 0 ;
$this->nb_item_pointe = 0 ;
$rqt_nb_item="select count(1) from ".static::get_table_content_name()." where ".static::get_field_content_name()."='".$this->get_idcaddie()."' ";
$this->nb_item = pmb_mysql_result(pmb_mysql_query($rqt_nb_item), 0, 0);
$rqt_nb_item_pointe = "select count(1) from ".static::get_table_content_name()." where ".static::get_field_content_name()."='".$this->get_idcaddie()."' and (flag is not null and flag!='') ";
$this->nb_item_pointe = pmb_mysql_result(pmb_mysql_query($rqt_nb_item_pointe), 0, 0);
}
public function add_items_by_collecte_selection($final_query) {
global $msg, $charset;
global $base_path;
global $erreur_explain_rqt;
global $pmb_procs_force_execution, $force_exec, $PMBuserid;
$nb_element_a_ajouter = 0;
$line = pmb_split("\n", $final_query);
$nb_element_avant = $this->nb_item;
foreach ($line as $cle => $valeur) {
if ($valeur != '') {
if ( (pmb_strtolower(pmb_substr($valeur,0,6))=="select") || (pmb_strtolower(pmb_substr($valeur,0,6))=="create")) {
} else {
echo pmb_substr($valeur,0,6);
error_message_history($msg['caddie_action_invalid_query'],$msg['requete_selection'],1);
exit();
}
if (!(($pmb_procs_force_execution && $force_exec) || (($PMBuserid == 1) && $force_exec) || explain_requete($valeur))) {
print "
".$valeur."
".$msg["proc_param_explain_failed"]."
".$erreur_explain_rqt;
if($pmb_procs_force_execution || $PMBuserid == 1) {
print "
";
}
die();
}
$result_selection = pmb_mysql_query($valeur);
if (!$result_selection) {
error_message_history($msg['caddie_action_invalid_query'],$msg['requete_echouee'].pmb_mysql_error(),1);
exit();
}
if (pmb_strtolower(pmb_substr($valeur,0,6))=="select") {
$nb_element_a_ajouter += pmb_mysql_num_rows($result_selection);
if(pmb_mysql_num_rows($result_selection)) {
while ($obj_selection = pmb_mysql_fetch_object($result_selection))
if(static::class == 'empr_caddie') {
$this->add_item($obj_selection->object_id);
} else {
$this->add_item($obj_selection->object_id,$obj_selection->object_type);
}
} // fin if mysql_num_rows
$this->compte_items();
} // fin if rqt sélection
} //fin valeur nonvide
} // fin while list $cle
$nb_element_apres = $this->nb_item;
$msg["caddie_affiche_nb_ajouts"] = str_replace('!!nb_a_ajouter!!', $nb_element_a_ajouter, $msg["caddie_affiche_nb_ajouts"]);
$msg["caddie_affiche_nb_ajouts"] = str_replace('!!nb_ajoutes!!', ($nb_element_apres-$nb_element_avant), $msg["caddie_affiche_nb_ajouts"]);
$res_exec = "