id = $id*1; } public function get_form() { global $admin_explnum_licence_profile_form, $msg, $charset; $form = $admin_explnum_licence_profile_form; $form = str_replace('!!id!!', $this->id*1, $form); $form = str_replace('!!explnum_licence_id!!', $this->explnum_licence_num, $form); if(!$this->id){ $form = str_replace('!!form_title!!', $msg['explnum_licence_profile_new'], $form); $form = str_replace('!!explnum_licence_profile_label!!', '', $form); $form = str_replace('!!explnum_licence_profile_uri!!', '', $form); $form = str_replace('!!explnum_licence_profile_logo_url!!', '', $form); $form = str_replace('!!explnum_licence_profile_explanation!!', '', $form); $form = str_replace('!!explnum_licence_profile_quotation_rights!!', '', $form); $form = str_replace('!!bouton_supprimer!!', '', $form); }else{ $form = str_replace('!!form_title!!', $msg['explnum_licence_profile_edit'], $form); $form = str_replace('!!explnum_licence_profile_label!!', htmlentities($this->label, ENT_QUOTES, $charset), $form); $form = str_replace('!!explnum_licence_profile_uri!!', htmlentities($this->uri, ENT_QUOTES, $charset), $form); $form = str_replace('!!explnum_licence_profile_logo_url!!', htmlentities($this->logo_url, ENT_QUOTES, $charset), $form); $form = str_replace('!!explnum_licence_profile_explanation!!', htmlentities($this->explanation, ENT_QUOTES, $charset), $form); $form = str_replace('!!explnum_licence_profile_quotation_rights!!', htmlentities($this->quotation_rights, ENT_QUOTES, $charset), $form); $form = str_replace('!!bouton_supprimer!!', '', $form); } $form = str_replace('!!explnum_licence_profile_linked_rights!!', $this->generate_rights_checkboxes(), $form); return $form; } public function get_values_from_form(){ global $explnum_licence_profile_label, $explnum_licence_profile_uri, $explnum_licence_profile_logo_url; global $explnum_licence_profile_explanation, $explnum_licence_profile_quotation_rights, $explnum_licence_profile_rights; $this->label = stripslashes($explnum_licence_profile_label); $this->uri = stripslashes($explnum_licence_profile_uri); $this->logo_url = stripslashes($explnum_licence_profile_logo_url); $this->explanation = stripslashes($explnum_licence_profile_explanation); $this->quotation_rights = stripslashes($explnum_licence_profile_quotation_rights); $this->rights = array(); if (is_array($explnum_licence_profile_rights)) { foreach ($explnum_licence_profile_rights as $right){ $this->rights[$right] = new explnum_licence_right($right); } } } public function save(){ $query = ''; $clause = ''; if($this->id){ $query.= 'update '; $clause = ' where id_explnum_licence_profile = '.$this->id; }else{ $query.= 'insert into '; } $query.= 'explnum_licence_profiles set explnum_licence_profile_explnum_licence_num = "'.addslashes($this->explnum_licence_num).'", explnum_licence_profile_label = "'.addslashes($this->label).'", explnum_licence_profile_uri = "'.addslashes($this->uri).'", explnum_licence_profile_logo_url = "'.addslashes($this->logo_url).'", explnum_licence_profile_explanation = "'.addslashes($this->explanation).'", explnum_licence_profile_quotation_rights = "'.addslashes($this->quotation_rights).'"'; $query.= $clause; pmb_mysql_query($query); if(!$this->id){ $this->id = pmb_mysql_insert_id(); } pmb_mysql_query('delete from explnum_licence_profile_rights where explnum_licence_profile_num = '.$this->id); $rights_ids = array_keys($this->rights); $query = ''; for($i=0 ; $iid.', '.$rights_ids[$i].') '; } if($query){ $query = 'insert into explnum_licence_profile_rights (explnum_licence_profile_num, explnum_licence_right_num) values '.$query; pmb_mysql_query($query); } } public function fetch_data() { if (!$this->id) { return false; } $query = 'select explnum_licence_profiles.explnum_licence_profile_explnum_licence_num, explnum_licence_profiles.explnum_licence_profile_label, explnum_licence_profiles.explnum_licence_profile_uri, explnum_licence_profiles.explnum_licence_profile_logo_url, explnum_licence_profiles.explnum_licence_profile_explanation, explnum_licence_profiles.explnum_licence_profile_quotation_rights from explnum_licence_profiles where explnum_licence_profiles.id_explnum_licence_profile = '.$this->id; $result = pmb_mysql_query($query); $row = pmb_mysql_fetch_assoc($result); if (count($row)) { $this->explnum_licence_num = $row['explnum_licence_profile_explnum_licence_num']; $this->label = $row['explnum_licence_profile_label']; $this->uri = $row['explnum_licence_profile_uri']; $this->logo_url = $row['explnum_licence_profile_logo_url']; $this->explanation = $row['explnum_licence_profile_explanation']; $this->quotation_rights = $row['explnum_licence_profile_quotation_rights']; } } public function delete($force = false) { if (!$this->id) { return false; } if($force || !$this->is_used()) { pmb_mysql_query('delete from explnum_licence_profile_explnums where explnum_licence_profile_explnums_profile_num = '.$this->id); pmb_mysql_query('delete from explnum_licence_profile_rights where explnum_licence_profile_num = '.$this->id); pmb_mysql_query('delete from explnum_licence_profiles where id_explnum_licence_profile = '.$this->id); return true; } return false; } public function set_explnum_licence_num($explnum_licence_num) { $this->explnum_licence_num = $explnum_licence_num*1; return $this; } public function is_used() { $result = pmb_mysql_query('select explnum_licence_profile_explnums_explnum_num from explnum_licence_profile_explnums where explnum_licence_profile_explnums_profile_num = '.$this->id.' limit 1'); if (pmb_mysql_num_rows($result)) { return true; } return false; } /** * @return explnum_licence_right */ public function get_rights(){ if(!isset($this->rights)){ $this->rights = array(); $query = 'select explnum_licence_right_num from explnum_licence_profile_rights where explnum_licence_profile_num = '.$this->id; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { while ($row = pmb_mysql_fetch_assoc($result)) { $this->rights[$row['explnum_licence_right_num']] = new explnum_licence_right($row['explnum_licence_right_num']); } } } return $this->rights; } protected function generate_rights_checkboxes(){ global $admin_explnum_checkbox_template, $msg; $explnum_licence = new explnum_licence($this->explnum_licence_num); $this->get_rights(); $used_rights = array_keys($this->rights); $rights_available = $explnum_licence->get_rights(); $html = ''; if (!count($rights_available)) { $html.= $msg['explnum_licence_no_right_defined']; } foreach($rights_available as $right){ $checkbox_template = str_replace('!!admin_explnum_right_label!!', $right->get_label(), $admin_explnum_checkbox_template); $checkbox_template = str_replace('!!admin_explnum_right_id!!', $right->get_id(), $checkbox_template); $checkbox_template = str_replace('!!admin_explnum_right_checked!!', (in_array($right->get_id(), $used_rights) ? ' checked="checked "' : ''), $checkbox_template); $html.= $checkbox_template; } return $html; } public function get_id() { return $this->id; } public function get_label() { if (!isset($this->label)) { $this->fetch_data(); } return $this->label; } public function get_logo_url() { if (!isset($this->logo_url)) { $this->fetch_data(); } return $this->logo_url; } public function get_uri() { if (!isset($this->uri)) { $this->fetch_data(); } return $this->uri; } public function get_explanation(){ return $this->explanation; } public function get_quotation_rights(){ return $this->quotation_rights; } }