public function login()
 {
     if (isset($this->request->query['returnurl'])) {
         //$this->request['url']['returnurl']
         $returnurl = $this->request->query['returnurl'];
     } else {
         $returnurl = ADMIN_HOME_URL;
     }
     $session_user_admin = $this->Session->read(SESSION_USER_ADMIN);
     if ($session_user_admin) {
         $this->redirect($returnurl);
         return;
     }
     $this->set('returnurl', $returnurl);
     // If login (submit) button is press
     if ($this->request->isPost()) {
         $admin_access_list_arr = GlobalVar::read("admin_access_list_arr");
         $username = $this->data['username'];
         $password = sha1($this->data['password']);
         if (isset($this->data['returnurl'])) {
             $returnurl = $this->data['returnurl'];
         }
         if (isset($admin_access_list_arr[$username]) && $admin_access_list_arr[$username] == $password) {
             $this->Session->write(SESSION_USER_ADMIN, $username);
             // save user to session
             $this->redirect($returnurl);
         }
     }
 }
 public function edit($id_user)
 {
     if ($this->request->isPost()) {
         $data = $this->request->data('user');
         $pass = $this->request->data('password');
         if ($pass != '') {
             $data['User']['password'] = md5($pass);
         }
         if ($this->User->save($data)) {
             $this->Session->setFlash(GlobalVar::get_html_success('Update profile successful'));
         } else {
             $this->Session->setFlash(GlobalVar::get_html_error('Update profile failed'));
         }
     }
     if ($user = $this->User->find('first', array('conditions' => array('id_user' => $id_user)))) {
         $this->set('Profile', $user);
     } else {
         $this->redirect(ROOT_URL . 'book/index');
     }
 }
// choose the type of the declaration according to your server settings (some servers don't accept the dirname(__FILE__) command for security reasons).
// NEW in 0.3 version : no more / at the end of $dirfonts and $dirimg
// absolute path to the fonts directory
class GlobalVar
{
    public static $dirfonts;
    public static $dirimg;
    public static $symboles;
    public static $fontesmath;
}
GlobalVar::$dirfonts = __DIR__ . "/fonts";
// absolute path to the images directory
GlobalVar::$dirimg = __DIR__ . "/img";
//******************************************************************
GlobalVar::$symboles = array('~' => ' ', 'alpha' => '&#174;', 'beta' => '&#175;', 'gamma' => '&#176;', 'delta' => '&#177;', 'epsilon' => '&#178;', 'varepsilon' => '&#34;', 'zeta' => '&#179;', 'eta' => '&#180;', 'theta' => '&#181;', 'vartheta' => '&#35;', 'iota' => '&#182;', 'kappa' => '&#183;', 'lambda' => '&#184;', 'mu' => '&#185;', 'nu' => '&#186;', 'xi' => '&#187;', 'pi' => '&#188;', 'varpi' => '&#36;', 'rho' => '&#189;', 'varrho' => '&#37;', 'sigma' => '&#190;', 'varsigma' => '&#38;', 'tau' => '&#191;', 'upsilon' => '&#192;', 'phi' => '&#193;', 'varphi' => '&#39;', 'chi' => '&#194;', 'psi' => '&#195;', 'omega' => '&#33;', 'Gamma' => '&#161;', 'Lambda' => '&#164;', 'Sigma' => '&#167;', 'Psi' => '&#170;', 'Delta' => '&#162;', 'Xi' => '&#165;', 'Upsilon' => '&#168;', 'Omega' => '&#173;', 'Theta' => '&#163;', 'Pi' => '&#166;', 'Phi' => '&#169;', 'infty' => '&#8734;', 'ne' => '&#8800;', '*' => '&#215;', 'in' => '&#8712;', 'notin' => '&#8713;', 'forall' => '&#8704;', 'exists' => '&#8707;', 'notexists' => '&#8708;', 'partial' => '&#8706;', 'approx' => '&#8776;', 'left' => '&#8592;', 'right' => '&#8594;', 'leftright' => '&#8596;', 'doubleleft' => '&#8656;', 'doubleright' => '&#8658;', 'doubleleftright' => '&#8660;', 'nearrow' => '&#8599;', 'searrow' => '&#8601;', 'pm' => '&#177;', 'bbR' => '&#8477;', 'bbN' => '&#8469;', 'bbZ' => '&#8484;', 'bbC' => '&#8450;', 'inter' => '&#8898;', 'union' => '&#8899;', 'ortho' => '&#8869;', 'parallel' => '&#8741;', 'backslash' => '&#92;', 'prime' => '&#39;', 'wedge' => '&#8896;', 'vert' => '&#8741;', 'subset' => '&#8834;', 'notsubset' => '&#8836;', 'circ' => '&#8728;', 'varnothing' => '&#248;', 'cdots' => '&#8943;', 'vdots' => '&#8942;', 'ddots' => '&#8945;', 'le' => '&#54;', 'ge' => '&#62;', '<' => '&#60;', '>' => '&#62;', '(' => '&#179;', ')' => '&#180;', '[' => '&#104;', ']' => '&#105;', 'lbrace' => '&#40;', 'rbrace' => '&#41;', '_hat' => '&#99;', '_racine' => '&#113;', '_integrale' => '&#82;', '_dintegrale' => '&#8748;', '_tintegrale' => '&#8749;', '_ointegrale' => '&#72;', '_produit' => '&#81;', '_somme' => '&#80;', '_intersection' => '&#84;', '_reunion' => '&#83;', '_lim' => 'lim', 'arccos' => 'arccos', 'ker' => 'ker', 'arcsin' => 'arcsin', 'lg' => 'lg', 'arctan' => 'arctan', 'arg' => 'arg', 'cos' => 'cos', 'cosh' => 'cosh', 'ln' => 'ln', 'cot' => 'cot', 'log' => 'log', 'coth' => 'coth', 'max' => 'max', 'csc' => 'csc', 'min' => 'min', 'deg' => 'deg', 'det' => 'det', 'sec' => 'sec', 'dim' => 'dim', 'sin' => 'sin', 'exp' => 'exp', 'sinh' => 'sinh', 'gcd' => 'gcd', 'sup' => 'sup', 'hom' => 'hom', 'tan' => 'tan', 'inf' => 'inf', 'tanh' => 'tanh');
GlobalVar::$fontesmath = array('~' => 'FreeSerif', 'alpha' => 'cmmi10', 'beta' => 'cmmi10', 'gamma' => 'cmmi10', 'delta' => 'cmmi10', 'epsilon' => 'cmmi10', 'varepsilon' => 'cmmi10', 'zeta' => 'cmmi10', 'eta' => 'cmmi10', 'theta' => 'cmmi10', 'vartheta' => 'cmmi10', 'iota' => 'cmmi10', 'kappa' => 'cmmi10', 'lambda' => 'cmmi10', 'mu' => 'cmmi10', 'nu' => 'cmmi10', 'xi' => 'cmmi10', 'pi' => 'cmmi10', 'varpi' => 'cmmi10', 'rho' => 'cmmi10', 'varrho' => 'cmmi10', 'sigma' => 'cmmi10', 'varsigma' => 'cmmi10', 'tau' => 'cmmi10', 'upsilon' => 'cmmi10', 'phi' => 'cmmi10', 'varphi' => 'cmmi10', 'chi' => 'cmmi10', 'psi' => 'cmmi10', 'omega' => 'cmmi10', 'Gamma' => 'cmr10', 'Lambda' => 'cmr10', 'Sigma' => 'cmr10', 'Psi' => 'cmr10', 'Delta' => 'cmr10', 'Xi' => 'cmr10', 'Upsilon' => 'cmr10', 'Omega' => 'cmr10', 'Theta' => 'cmr10', 'Pi' => 'cmr10', 'Phi' => 'cmr10', 'infty' => 'FreeSerif', 'ne' => 'FreeSerif', '*' => 'FreeSerif', 'in' => 'FreeSerif', 'notin' => 'FreeSerif', 'forall' => 'FreeSerif', 'exists' => 'FreeSerif', 'notexists' => 'FreeSerif', 'partial' => 'FreeSerif', 'approx' => 'FreeSerif', 'left' => 'FreeSerif', 'right' => 'FreeSerif', 'leftright' => 'FreeSerif', 'doubleleft' => 'FreeSerif', 'doubleright' => 'FreeSerif', 'doubleleftright' => 'FreeSerif', 'nearrow' => 'FreeSerif', 'searrow' => 'FreeSerif', 'pm' => 'FreeSerif', 'bbR' => 'FreeSerif', 'bbN' => 'FreeSerif', 'bbZ' => 'FreeSerif', 'bbC' => 'FreeSerif', 'inter' => 'FreeSerif', 'union' => 'FreeSerif', 'ortho' => 'FreeSerif', 'parallel' => 'FreeSerif', 'backslash' => 'FreeSerif', 'prime' => 'FreeSerif', 'wedge' => 'FreeSerif', 'vert' => 'FreeSerif', 'subset' => 'FreeSerif', 'notsubset' => 'FreeSerif', 'circ' => 'FreeSerif', 'varnothing' => 'FreeSerif', 'cdots' => 'FreeSerif', 'vdots' => 'FreeSerif', 'ddots' => 'FreeSerif', 'le' => 'msam10', 'ge' => 'msam10', '<' => 'cmmi10', '>' => 'cmmi10', '(' => 'cmex10', ')' => 'cmex10', '[' => 'cmex10', ']' => 'cmex10', 'lbrace' => 'cmex10', 'rbrace' => 'cmex10', '_hat' => 'cmex10', '_racine' => 'cmex10', '_integrale' => 'cmex10', '_dintegrale' => 'FreeSerif', '_tintegrale' => 'FreeSerif', '_ointegrale' => 'cmex10', '_produit' => 'cmex10', '_somme' => 'cmex10', '_intersection' => 'cmex10', '_reunion' => 'cmex10', '_lim' => 'cmr10', 'arccos' => 'cmr10', 'ker' => 'cmr10', 'arcsin' => 'cmr10', 'lg' => 'cmr10', 'arctan' => 'cmr10', 'arg' => 'cmr10', 'cos' => 'cmr10', 'cosh' => 'cmr10', 'ln' => 'cmr10', 'cot' => 'cmr10', 'log' => 'cmr10', 'coth' => 'cmr10', 'max' => 'cmr10', 'csc' => 'cmr10', 'min' => 'cmr10', 'deg' => 'cmr10', 'det' => 'cmr10', 'sec' => 'cmr10', 'dim' => 'cmr10', 'sin' => 'cmr10', 'exp' => 'cmr10', 'sinh' => 'cmr10', 'gcd' => 'cmr10', 'sup' => 'cmr10', 'hom' => 'cmr10', 'tan' => 'cmr10', 'inf' => 'cmr10', 'tanh' => 'cmr10');
function est_nombre($str)
{
    return preg_match("/^[0-9]/", $str);
}
function tableau_expression($expression)
{
    $e = str_replace('_', ' _ ', $expression);
    $e = str_replace('{(}', '{ }', $e);
    $e = str_replace('{)}', '{ }', $e);
    $t = token_get_all("<?php \$formula={$e} ?" . ">");
    $extraits = array();
    $result = array();
    //stupid code but token_get_all bug in some php versions
    $d = 0;
    for ($i = 0; $i < count($t); $i++) {
 public function edit($id = null)
 {
     $this->set('title_for_layout', ' Edit Author');
     $success_message = '';
     if ($this->request->isPost()) {
         if (isset($this->data['cancel'])) {
             $this->redirect(ADMIN_ROOT_URL . 'adminauthor/index');
             return;
         }
         if (isset($this->data['editauthor'])) {
             if (isset($this->params['form']['image']['name']) && !empty($this->params['form']['image']['name'])) {
                 $new_name = $this->params['form']['image']['name'];
                 $uploader = new ImageUploader(IMAGE_UPLOAD_PATH_AUTHOR, $this->params['form']['image'], $id, $this->img_check_pattern);
                 $upload_result = $uploader->upload();
                 if (!$upload_result) {
                     $upload_image_err = $uploader->get_error_message();
                     $msg = "You can not upload images。";
                     $this->set('errors_image', $upload_image_err);
                 } else {
                     $img = $id . '.' . $this->img_check_pattern['ext'];
                     $this->Author->save(array('id_author' => $id, 'img' => $img));
                 }
             }
             $this->Author->save(array('id_author' => $id, 'name' => $this->request->data('name'), 'biography' => $this->request->data('biography')));
             $success_message = 'Update succeed。';
             $this->Session->setFlash(GlobalVar::get_html_success($success_message));
         }
     }
     $authorupdate = $this->Author->find('first', array('conditions' => array('id_author' => $id)));
     $this->set('Author', $authorupdate);
 }
 public function add()
 {
     $this->set('title_for_layout', 'Add Book');
     if ($this->request->isPost()) {
         if ($this->Author->find('first', array('conditions' => array('id_author' => $this->request->data['id_author'])))) {
             if (!$this->Book->find('first', array('conditions' => array('id_book' => $this->request->data['id_book'])))) {
                 if (isset($this->params['form']['image']['name']) && !empty($this->params['form']['image']['name'])) {
                     $new_name = $this->params['form']['image']['name'];
                     $uploader = new ImageUploader(IMAGE_UPLOAD_PATH_BOOK, $this->params['form']['image'], $this->request->data('id_user'), $this->img_check_pattern);
                     $upload_result = $uploader->upload();
                     if (!$upload_result) {
                         $upload_image_err = $uploader->get_error_message();
                         $msg = "You can not upload images。";
                         $this->set('errors_image', $upload_image_err);
                     } else {
                         $img = $this->request->data('id_user') . '.' . $this->img_check_pattern['ext'];
                         $this->User->save(array('id_user' => $this->request->data('id_user'), 'avatar' => $img));
                     }
                     if ($this->Wrote->save(array('id_author' => $this->request->data('id_author'), 'id_book' => $this->request->data('id_book')))) {
                         $remain = $this->request->data('price') * (100 - $this->request->data('remain')) / 100;
                         if (!$this->request->data('adult')) {
                             $adult = 0;
                         } else {
                             $adult = $this->request->data('adult');
                         }
                         if (!$this->request->data('ebook')) {
                             $adult = 0;
                         } else {
                             $adult = $this->request->data('ebook');
                         }
                         if ($this->request->data('book')) {
                             $adult = 1;
                         } else {
                             $adult = $this->request->data('book');
                         }
                         if ($this->Book->save(array('id_book' => $this->request->data('id_book'), 'name' => $this->request->data('name'), 'description' => $this->request->data('description'), 'descriptionpro' => $this->request->data('descriptionpro'), 'description404' => $this->request->data('description404'), 'sale' => $this->request->data('remain'), 'price' => $this->request->data('price'), 'remain' => $remain, 'adult' => $this->request->data('adult'), 'ebook' => $this->request->data('ebook'), 'book' => $this->request->data('book')))) {
                             $this->Session->setFlash(GlobalVar::get_html_success("Add Book succeed"));
                             $this->redirect(ADMIN_ROOT_URL . 'adminbook/index');
                             exit;
                         } else {
                             $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
                             exit;
                         }
                     } else {
                         $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
                         exit;
                     }
                 }
             }
         } else {
             $this->Session->setFlash(GlobalVar::get_html_error("This author's id  not existed "));
             exit;
         }
     }
 }
 public function add()
 {
     $this->set('title_for_layout', ' Add User');
     $success_message = '';
     if ($this->request->isPost()) {
         if (isset($this->data['cancel'])) {
             $this->redirect(ADMIN_ROOT_URL . 'adminusers/index');
             return;
         }
         if (isset($this->data['adduser'])) {
             if (isset($this->params['form']['image']['name']) && !empty($this->params['form']['image']['name'])) {
                 $new_name = $this->params['form']['image']['name'];
                 $uploader = new ImageUploader(IMAGE_UPLOAD_PATH_USER, $this->params['form']['image'], $this->request->data('id_user'), $this->img_check_pattern);
                 $upload_result = $uploader->upload();
                 if (!$upload_result) {
                     $upload_image_err = $uploader->get_error_message();
                     $msg = "You can not upload images。";
                     $this->set('errors_image', $upload_image_err);
                 } else {
                     $img = $this->request->data('id_user') . '.' . $this->img_check_pattern['ext'];
                     $this->User->save(array('id_user' => $this->request->data('id_user'), 'avatar' => $img));
                 }
             }
             if ($this->User->save(array('id_user' => $this->request->data('id_user'), 'username' => $this->request->data('username'), 'password' => sha1($this->request->data('password')), 'birth' => $this->request->data('birth'), 'mail' => $this->request->data('mail'), 'sex' => $this->request->data('gender'), 'mail' => $this->request->data('mail'), 'facebook' => $this->request->data('facebook'), 'balance' => $this->request->data('balance'), 'created' => $this->request->data('created'), 'nearest' => $this->request->data('nearest')))) {
                 $success_message = 'Add succeed。';
                 $this->Session->setFlash(GlobalVar::get_html_success($success_message));
             } else {
                 $success_message = 'Add failed。';
                 $this->Session->setFlash(GlobalVar::get_html_success($success_message));
             }
         }
     }
 }