/** * @access private * Vérification de la session pour accèder à l'administration * @param bool $debug */ private function authSession($debug = false) { //Language model init class $language = new backend_model_language(); $language->run(); $token = isset($_SESSION['mc_auth_token']) ? $_SESSION['mc_auth_token'] : magixglobal_model_cryptrsa::tokenId(); $tokentools = $this->hashPassCreate($token); backend_controller_template::assign('hashpass', $tokentools); if (isset($this->email_admin) and isset($this->passwd_admin) and isset($this->hashtoken)) { if (strcasecmp($this->hashtoken, $tokentools) == 0) { if ($debug == true) { $firebug = new magixcjquery_debug_magixfire(); $firebug->magixFireGroup('tokentest'); if ($this->hashtoken) { if (strcasecmp($this->hashtoken, $tokentools) == 0) { $firebug->magixFireLog('session compatible'); } else { $firebug->magixFireError('session incompatible'); } } $firebug->magixFireLog($_SESSION); $firebug->magixFireGroupEnd(); } $auth_exist = parent::s_auth_exist($this->email_admin, $this->passwd_admin); if (count($auth_exist['id_admin']) == true) { $session = new backend_model_sessions(); $lang = new backend_model_language(); $string = $_SERVER['HTTP_USER_AGENT']; $string .= 'SHIFLETT'; /* Add any other data that is consistent */ $fingerprint = md5($string); //Fermeture de la première session, ses données sont sauvegardées. session_write_close(); $this->start_session(); $data = parent::s_data_session($auth_exist['keyuniqid_admin']); if (!isset($_SESSION['email_admin']) and !isset($_SESSION['keyuniqid_admin'])) { $lang = new backend_model_language(); $session->openSession($data['id_admin'], session_regenerate_id(true), $data['keyuniqid_admin']); //session_regenerate_id(true); $_SESSION['id_admin'] = $data['id_admin']; $_SESSION['email_admin'] = $data['email_admin']; $_SESSION['keyuniqid_admin'] = $data['keyuniqid_admin']; $_SESSION['adminLanguage'] = $lang->run(); if ($debug == true) { $firebug = new magixcjquery_debug_magixfire(); $firebug->magixFireGroup('adminsession'); $firebug->magixFireDump('User session', $_SESSION); $firebug->magixFireGroupEnd(); } magixglobal_model_redirect::backend_redirect_login(false); } else { $session->openSession($data['id_admin'], null, $data['keyuniqid_admin']); $_SESSION['id_admin'] = $data['id_admin']; $_SESSION['email_admin'] = $data['email_admin']; $_SESSION['keyuniqid_admin'] = $data['keyuniqid_admin']; $_SESSION['adminLanguage'] = $lang->run(); if ($debug == true) { $firebug = new magixcjquery_debug_magixfire(); $firebug->magixFireGroup('adminsession'); $firebug->magixFireDump('User session', $_SESSION); $firebug->magixFireGroupEnd(); } magixglobal_model_redirect::backend_redirect_login(false); } } else { $this->message->getNotify('error_login', array('method' => 'fetch', 'assignFetch' => 'login_message')); } } else { $this->message->getNotify('error_hash', array('method' => 'fetch', 'assignFetch' => 'login_message')); } } }
/** * @access public * Affiche le debug pour les sessions */ public function debug() { if (M_FIREPHP) { $firebug = new magixcjquery_debug_magixfire(); $firebug->magixFireGroup('Magix Session'); //$firebug->magixFireLog($_SESSION); $firebug->magixFireDump('session run', $_SESSION); $firebug->magixFireGroupEnd(); } else { var_dump($_SESSION); } }
/** * Insertion d'une image dans la galerie spécifique à un produit * @param $img * @param $imgcatalog * @param bool $debug * @return string * @throws Exception */ private function insert_image_galery($img, $imgcatalog, $debug = false) { if (isset($this->{$img})) { try { //Supprime le fichier original pour gagner en espace $makeFiles = new magixcjquery_files_makefiles(); // Charge la classe de traitement des images $initImg = new backend_model_image(); /** * Envoi une image dans le dossier "racine" catalogimg */ $initImg->upload_img('imgcatalog', 'upload' . DIRECTORY_SEPARATOR . 'catalogimg' . DIRECTORY_SEPARATOR . 'galery' . DIRECTORY_SEPARATOR, $debug); /** * Analyze l'extension du fichier en traitement * @var $fileextends */ $fileextends = $initImg->image_analyze(self::dirImgProductGalery() . $this->{$img}); if ($initImg->imgSizeMin(self::dirImgProductGalery() . $this->{$img}, 25, 25)) { // Charge la classe pour renommer le fichier $makeFiles = new magixcjquery_files_makefiles(); /* * Renomme le fichier */ $makeFiles->renameFiles(self::dirImgProductGalery(), self::dirImgProductGalery() . $this->{$img}, self::dirImgProductGalery() . $imgcatalog . $fileextends); /** * Initialisation de la classe phpthumb * @var void */ $thumb = PhpThumbFactory::create(self::dirImgProductGalery() . $imgcatalog . $fileextends); //Charge la taille des images des galeries du catalogue $firebug = new magixcjquery_debug_magixfire(); /** * Création des images et miniatures utile. * 2 tailles !!! */ $imgsizelarge = $initImg->dataImgSize('catalog', 'galery', 'large'); $imgsizesmall = $initImg->dataImgSize('catalog', 'galery', 'small'); if ($debug) { $firebug->magixFireGroup('Setting image'); } switch ($imgsizelarge['img_resizing']) { case 'basic': if ($debug) { $firebug->magixFireGroup($imgsizelarge['config_size_attr'] . ' => ' . $imgsizelarge['type']); $firebug->magixFireLog($imgsizelarge['img_resizing'], 'Type'); $firebug->magixFireLog($imgsizelarge['width'], 'Width'); $firebug->magixFireLog($imgsizelarge['height'], 'Height'); $firebug->magixFireGroupEnd(); } $thumb->resize($imgsizelarge['width'], $imgsizelarge['height'])->save(self::dirImgProductGalery() . 'maxi' . DIRECTORY_SEPARATOR . $imgcatalog . $fileextends); break; case 'adaptive': if ($debug) { $firebug->magixFireGroup($imgsizelarge['config_size_attr'] . ' => ' . $imgsizelarge['type']); $firebug->magixFireLog($imgsizelarge['img_resizing'], 'Type'); $firebug->magixFireLog($imgsizelarge['width'], 'Width'); $firebug->magixFireLog($imgsizelarge['height'], 'Height'); $firebug->magixFireGroupEnd(); } $thumb->adaptiveResize($imgsizelarge['width'], $imgsizelarge['height'])->save(self::dirImgProductGalery() . 'maxi' . DIRECTORY_SEPARATOR . $imgcatalog . $fileextends); break; } switch ($imgsizesmall['img_resizing']) { case 'basic': if ($debug) { $firebug->magixFireGroup($imgsizesmall['config_size_attr'] . ' => ' . $imgsizesmall['type']); $firebug->magixFireLog($imgsizesmall['img_resizing'], 'Type'); $firebug->magixFireLog($imgsizesmall['width'], 'Width'); $firebug->magixFireLog($imgsizesmall['height'], 'Height'); $firebug->magixFireGroupEnd(); } $thumb->resize($imgsizesmall['width'], $imgsizesmall['height'])->save(self::dirImgProductGalery() . 'mini' . DIRECTORY_SEPARATOR . $imgcatalog . $fileextends); break; case 'adaptive': if ($debug) { $firebug->magixFireGroup($imgsizesmall['config_size_attr'] . ' => ' . $imgsizesmall['type']); $firebug->magixFireLog($imgsizesmall['img_resizing'], 'Type'); $firebug->magixFireLog($imgsizesmall['width'], 'Width'); $firebug->magixFireLog($imgsizesmall['height'], 'Height'); $firebug->magixFireGroupEnd(); } $thumb->adaptiveResize($imgsizesmall['width'], $imgsizesmall['height'])->save(self::dirImgProductGalery() . 'mini' . DIRECTORY_SEPARATOR . $imgcatalog . $fileextends); break; } if ($debug) { $firebug->magixFireGroupEnd(); } if (file_exists(self::dirImgProductGalery() . $imgcatalog . $fileextends)) { $makeFiles->removeFile(self::dirImgProductGalery(), $imgcatalog . $fileextends); } return $imgcatalog . $fileextends; } else { if (file_exists(self::dirImgProductGalery() . $this->{$img})) { $makeFiles->removeFile(self::dirImgProductGalery(), $this->{$img}); } else { throw new Exception('file: ' . $this->{$img} . ' is not found'); } } } catch (Exception $e) { magixglobal_model_system::magixlog('An error has occured :', $e); } } }
/** * Upload une image * @param files $img * @param dir $path * @param bool $debug * @return null|string */ public static function upload_img($img, $path, $debug = false) { $error = null; $firebug = new magixcjquery_debug_magixfire(); if (isset($_FILES[$img])) { if ($_FILES[$img]['error'] == UPLOAD_ERR_OK) { if (self::image_valid($_FILES[$img]['tmp_name']) === false) { $error .= 'Mauvais format d\'image (gif,png,jpeg uniquement)'; } else { if (!is_readable($_FILES[$img]["tmp_name"])) { $tmp_img = chmod($_FILES[$img]["tmp_name"], 0777); } else { $tmp_img = $_FILES[$img]["tmp_name"]; } //if(chmod($_FILES[$img]["tmp_name"],0777)){ if (is_uploaded_file($_FILES[$img]["tmp_name"])) { $source = $tmp_img; $cible = magixglobal_model_system::base_path() . $path . magixcjquery_url_clean::rplMagixString($_FILES[$img]["name"]); if (self::imgSizeMax($source, 2500, 2500) == false) { $error .= 'La taille maximum excéde'; } elseif (self::imgSizeMin($source, 5, 5) == false) { $error .= 'Le fichier est trop petit'; } else { if (!move_uploaded_file($source, $cible)) { $error .= 'Erreur de fichier temporaire'; } else { if ($debug != false) { $firebug->magixFireGroup('Upload image infos'); $firebug->magixFireLog('Success', 'Status'); $firebug->magixFireLog($source, 'Source'); $firebug->magixFireLog($cible, 'Cible'); $firebug->magixFireGroupEnd(); } } } } else { $error .= 'Erreur d\'écriture du disque'; } //} } } elseif (UPLOAD_ERR_INI_SIZE == true) { $error .= 'Le fichier est trop grand'; } elseif (UPLOAD_ERR_CANT_WRITE == true) { $error .= 'Erreur d\'écriture du disque'; } elseif (UPLOAD_ERR_FORM_SIZE == true) { $error .= 'Le fichier est trop grand: Taille maximum 2000x2000'; } } elseif (UPLOAD_ERR_NO_FILE == true) { $error .= 'Aucun fichier'; } else { $error .= 'Erreur d\'écriture du disque'; } if ($error != null) { $n = $firebug->magixFireGroup('Upload image analyse'); $n .= $firebug->magixFireLog($error); $n .= $firebug->magixFireGroupEnd(); } else { $n = NULL; } return $n; }
/** * function debug pagination * * @param void $page * @param void $num_pages * @param int $limit * @param void $getpage */ private function debugPager($page, $num_pages, $limit, $getpage) { /*debug*/ if (defined('M_LOG')) { if (M_LOG == 'debug' and M_FIREPHP == true) { $FirePHPOpt = array('Collapsed' => false, 'Color' => '#FF772F'); magixcjquery_debug_magixfire::magixFireGroup('Test pagination', $FirePHPOpt); magixcjquery_debug_magixfire::magixFireLog($page, 'Page'); magixcjquery_debug_magixfire::magixFireLog($num_pages, 'Page number'); magixcjquery_debug_magixfire::magixFireLog($limit, 'Limit'); magixcjquery_debug_magixfire::magixFireGroupEnd(); $page = max($getpage, 1); magixcjquery_debug_magixfire::magixFireGroup('Test pagination', $FirePHPOpt); magixcjquery_debug_magixfire::magixFireLog($page, 'Page'); magixcjquery_debug_magixfire::magixFireLog($num_pages, 'Page number'); magixcjquery_debug_magixfire::magixFireLog($limit, 'Limit'); magixcjquery_debug_magixfire::magixFireGroupEnd(); $page = min($getpage, $num_pages); magixcjquery_debug_magixfire::magixFireGroup('Test pagination', $FirePHPOpt); magixcjquery_debug_magixfire::magixFireLog($page, 'Page'); magixcjquery_debug_magixfire::magixFireLog($num_pages, 'Page number'); magixcjquery_debug_magixfire::magixFireLog($limit, 'Limit'); magixcjquery_debug_magixfire::magixFireGroupEnd(); if ($getpage > $limit || $getpage <= 0) { $page = 1; } magixcjquery_debug_magixfire::magixFireGroup('Test pagination', $FirePHPOpt); magixcjquery_debug_magixfire::magixFireLog($page, 'Page'); magixcjquery_debug_magixfire::magixFireLog($num_pages, 'Page number'); magixcjquery_debug_magixfire::magixFireLog($limit, 'Limit'); magixcjquery_debug_magixfire::magixFireGroupEnd(); } } else { print 'Page : ' . $page . '<br />Num_Pages : ' . $num_pages . '<br />Limit : ' . $limit . '##########<br />'; $page = max($getpage, 1); print 'Page : ' . $page . '<br />Num_Pages : ' . $num_pages . '<br />Limit : ' . $limit . '##########<br />'; $page = min($getpage, $num_pages); print 'Page : ' . $page . '<br />Num_Pages : ' . $num_pages . '<br />Limit : ' . $limit . '##########<br />'; if ($getpage > $limit || $getpage <= 0) { $page = 1; } print 'Page : ' . $page . '<br />Num_Pages : ' . $num_pages . '<br />Limit : ' . $limit . '##########<br />'; } }