Exemple #1
0
 public static function getUserNotConfirmed()
 {
     $_SQL = Singleton::getInstance(SQL_DRIVER);
     $sql = "SELECT * FROM user_main WHERE (id_group = 1 and key_auth != '') OR id =3";
     $res = $_SQL->sql_query($sql);
     while ($ob = $_SQL->sql_fetch_object($res)) {
         $url = "http://www.estrildidae.net/user/confirmation/" . $ob->email . "/" . $ob->key_auth . "/";
         echo $url . "\n";
         $subject = __("Confirm your registration on www.estrildidae.net");
         $msg = __('Hello') . ' ' . $ob->firstname . ' ' . $ob->name . ' !<br />
             ' . __('Thank you for registering on estrildidae.net.') . '<br />
             <br />
             ' . __("To finalise your registration, please click on the confirmation link below. Once you've done this, your registration will be complete.") . '<br />
             ' . __('Please') . ' <a href="' . $url . '"> ' . __('click here') . '</a> ' . __('to confirm your registration
             or copy and paste the following URL into your browser:') . '
             ' . $url . '<br />
             <br />
             ' . __('Many thanks');
         $msg = $GLOBALS['_LG']->getTranslation($msg);
         $headers = 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
         // En-tetes additionnels
         $headers .= 'To: ' . $ob->firstname . ' ' . $ob->name . ' <' . $ob->email . '>' . "\r\n";
         $headers .= 'From: Aurélien LEQUOY <*****@*****.**>' . "\r\n";
         //$headers .= 'Cc: anniversaire_archive@example.com' . "\r\n";
         //$headers .= 'Bcc: anniversaire_verif@example.com' . "\r\n";
         mail($ob->email, $subject, $msg, $headers) or die("error mail");
     }
 }
 function insert($param)
 {
     debug($param);
     $this->view = false;
     $this->layout_name = false;
     $_SQL = Singleton::getInstance(SQL_DRIVER);
     $stats = new SynapseStatistics();
     $stats->decode64DeflateUnserialize($param[0]);
     $data = $stats->get();
     debug($data);
 }
Exemple #3
0
 public function sql_save($data = null, $replace = false)
 {
     if ($replace) {
         $insert_or_replace = 'REPLACE';
     } else {
         $insert_or_replace = 'INSERT';
     }
     unset($this->error);
     $this->error = array();
     if (count($this->_keys) === 0) {
         $this->unserializeKeys();
     }
     $table = array_keys($data);
     $table = $table[0];
     $keys = array_keys($data[$table]);
     $this->getInfosTable($table);
     $validation = new Validation($this);
     include_once APP_DIR . DS . "model" . DS . "Identifier" . ucwords(strtolower($this->_name)) . DS . $table . ".php";
     $model_name = "Identifier" . Inflector::camelize($this->_name);
     $table2 = str_replace("-", "", $table);
     //$my_table = singleton::getInstance('glial\synapse\model\table\\'.$table2);
     $my_table = Singleton::getInstance('application\\model\\' . $model_name . '\\' . $table2);
     $validate = $my_table->validate;
     //debug($validate);
     foreach ($keys as $field) {
         if (!empty($validate[$field])) {
             foreach ($validate[$field] as $rule => $param) {
                 if (!empty($rule)) {
                     $elem['table'] = $table;
                     $elem['field'] = $field;
                     $elem['value'] = $data[$table][$field];
                     if (in_array("id", $keys, true)) {
                         $elem['id'] = "AND id != " . $data[$table]['id'];
                     }
                     if (!empty($param[0])) {
                         $msg_error = $param[0];
                     } else {
                         $msg_error = NULL;
                     }
                     unset($param[0]);
                     if (!empty($param)) {
                         if (is_array($param)) {
                             $nb_var = count($param);
                             switch ($nb_var) {
                                 case 0:
                                     $return = $validation->{$rule}($elem);
                                     break;
                                 case 1:
                                     $return = $validation->{$rule}($elem, $param[1]);
                                     break;
                                 case 2:
                                     $return = $validation->{$rule}($elem, $param[1], $param[2]);
                                     break;
                                 case 3:
                                     $return = $validation->{$rule}($elem, $param[1], $param[2], $param[3]);
                                     break;
                             }
                         } else {
                             $return = $validation->{$rule}($elem, $param);
                         }
                     } else {
                         $return = $validation->{$rule}($elem);
                     }
                     if ($return === false) {
                         //$this->error[$table][$field][] = __($param['message']);
                         $this->error[$table][$field] = $msg_error;
                     }
                 }
             }
         }
     }
     unset($validation);
     $nb = count($keys);
     for ($i = 0; $i < $nb; $i++) {
         if (!in_array($keys[$i], $this->_table[$table]['field'])) {
             unset($data[$table][$keys[$i]]);
             unset($keys[$i]);
         } else {
             $data[$table][$keys[$i]] = $this->sql_real_escape_string($data[$table][$keys[$i]]);
         }
     }
     if (count($this->error) == 0) {
         if ($this->_history_active) {
             //traitement specifique
             if (strstr($this->_table_to_history, $table)) {
                 if (in_array("id", $keys, true)) {
                     $sql = "SELECT * FROM " . static::ESC . "" . $table . "" . static::ESC . " WHERE id ='" . $data[$table]['id'] . "'";
                     $res = $this->sql_query($sql);
                     if ($this->sql_num_rows($res) === 1) {
                         $before_update = $this->sql_to_array($res);
                         //\history::insert($table, $data[$table]['id'], $param, $this->_history_type);
                     }
                 }
             }
         }
         if (in_array("id", $keys, true)) {
             $id = $data[$table]['id'];
             unset($data[$table]['id']);
             $str = array();
             foreach ($keys as $key) {
                 if ($key === 'id') {
                     continue;
                 }
                 $str[] = "" . static::ESC . "" . $key . "" . static::ESC . " = '" . $data[$table][$key] . "'";
             }
             $sql = "UPDATE " . static::ESC . "" . $table . "" . static::ESC . " SET " . implode(",", $str) . " WHERE id= " . $this->sql_real_escape_string($id) . "";
             $this->sql_query($sql, $table, "UPDATE");
             if ($this->query[$this->number_of_query - 1]['rows'] === 0) {
                 $this->query[$this->number_of_query - 1]['last_id'] = $id;
             }
             // have to see if any problem in update
             /*
                             if ($this->query[$this->number_of_query - 1]['rows'] == 0) {
                                 //$sql = "INSERT INTO ".static::ESC."".$table."".static::ESC." SET ".implode(",", $str)."";
                                 //$sql = "INSERT INTO ".static::ESC."".$table."".static::ESC." (".implode(",", $keys).") VALUES (".$this->sql_real_escape_string($id).",'".implode("','", $data[$table])."') --";
                                 $sql = $insert_or_replace . " INTO " . static::ESC . "" . $table . "" . static::ESC . " SET id=" . $this->sql_real_escape_string($id) . " , " . implode(",", $str) . ""; //not supported by sybase A améliorer
                                 $this->sql_query($sql, $table, "INSERT");
                             }*/
         } else {
             $sql = $insert_or_replace . " INTO " . static::ESC . "" . $table . "" . static::ESC . " (" . static::ESC . "" . implode("" . static::ESC . "," . static::ESC . "", $keys) . "" . static::ESC . ") VALUES ('" . implode("','", $data[$table]) . "') --";
             //debug($sql);
             $this->sql_query($sql, $table, "INSERT");
         }
         if (static::ESC === '`') {
             //case where ignore insert 0 line and we need the id inserted with these infos, focus on index unique
             $this->last_id = $this->query[$this->number_of_query - 1]['last_id'];
             if ($this->last_id == 0) {
                 $sql = "SELECT id FROM " . static::ESC . "" . $table . "" . static::ESC . " WHERE 1=1 ";
                 if (!empty($this->_keys[$table])) {
                     foreach ($data[$table] as $key => $value) {
                         //select only unique key
                         if (in_array($key, $this->_keys[$table])) {
                             $sql .= " AND " . static::ESC . "" . $key . "" . static::ESC . " = '" . $value . "' ";
                         }
                     }
                 }
                 //debug($sql);
                 $res = $this->sql_query($sql, $table, "SELECT");
                 $tab = $this->sql_to_array($res);
                 if (!empty($tab[0]['id'])) {
                     $this->last_id = $tab[0]['id'];
                 } else {
                     $this->error[] = $sql;
                     $this->error[] = "impossible to select the right row plz have a look on date('c')";
                     throw new \Exception('GLI-031 : Impossible to fine last id inserted in case of insert ignore');
                 }
             }
         }
         if ($this->_history_active) {
             //traitement specifique
             if (strstr($this->_table_to_history, $table)) {
                 if (!empty($before_update)) {
                     $param = \history::compare($before_update[0], $data[$table]);
                     $id_table = $id;
                     $type_query = 'UPDATE';
                 } else {
                     $param = \history::compare(array(), $data[$table]);
                     $id_table = $this->last_id;
                     $type_query = 'INSERT';
                 }
                 \history::insert($table, $id_table, $param, $this->_history_type, $this->_history_user, $type_query);
                 $this->_history_type = HISTORY_TYPE;
                 $this->_history_user = null;
                 $this->last_id = $id_table;
             }
         }
         //return $this->query[$this->number_of_query-1]['last_id'];
         if (static::ESC === '"') {
             return true;
         } else {
             return $this->sql_insert_id();
         }
     } else {
         return false;
     }
 }
Exemple #4
0
 public static function get($id, $source)
 {
     $sql = "select c.id_species_author, x.surname, b.id as id_link,b.id,c.miniature ,\n\t\t\t(select count(1) as cpt from link__species_picture_id__species_picture_search f where  c.id = f.id_species_picture_id) as gg,\n\t\t\n\t\t\t(select count(1) as cpt from link__species_picture_id__species_picture_search i\n\t\t\tinner join species_picture_search j ON j.id = i.id_species_picture_search\n\t\t\twhere  c.id = i.id_species_picture_id AND j.id_species_main = a.id_species_main) as gg2,\n\t\t\tGROUP_CONCAT(DISTINCT a.tag_search ORDER BY a.tag_search DESC SEPARATOR '\n') as tag_search,\n\t\t\t\n\t\t\t(SELECT GROUP_CONCAT(DISTINCT t.scientific_name ORDER BY t.scientific_name DESC SEPARATOR '\n')\n\t\t\tFROM link__species_picture_id__species_picture_search r\n\t\t\tINNER JOIN species_picture_id s ON s.id = r.id_species_picture_id\n\t\t\tINNER JOIN species_picture_search u ON u.id = r.id_species_picture_search\n\t\t\tINNER JOIN species_main t ON t.id = u.id_species_main\n\t\t\tWHERE b.id_species_picture_id = s.id) as species\n\t\t\t\n\t\t\t\n    from species_picture_search a\n    inner join link__species_picture_id__species_picture_search b ON a.id = b.id_species_picture_search\n    inner join  species_picture_id c ON c.id = b.id_species_picture_id\n\tinner join species_main z ON z.id = a.id_species_main\n\tinner join species_author x ON x.id = c.id_species_author\n    inner JOIN species_source_main n ON n.id = a.id_species_source_main\n\n\t\n    where z.scientific_name = '" . str_replace('_', ' ', $id) . "'\n        AND n.name ='" . $source . "'\n\tgroup by x.id, b.id_species_picture_id\n    order by  c.id_species_author, c.photo_id limit 50";
     //echo $sql;
     $_SQL = Singleton::getInstance(SQL_DRIVER);
     $res = $_SQL->sql_query($sql);
     $data = $_SQL->sql_to_array($res);
     return $data;
 }