Пример #1
0
 /**
  * Performs the logic for logging into the LWS backend CMS.
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->setLayout('login');
     if ($request->isMethod('POST')) {
         $dao = new DAO();
         $pw = md5($dao->getEscapedSQLString(trim($request->getPostParameter('pw'))));
         $email = $dao->getEscapedSQLString(trim(strtolower($request->getPostParameter('email'))));
         $dao->query("\n  \t\t\tSELECT be_user.*, role \n  \t\t\tFROM be_user INNER JOIN be_role USING(role_id) \n  \t\t\tWHERE email='{$email}' AND password='******' LIMIT 1\n  \t\t");
         if ($dao->queryOK()) {
             $user = $dao->next();
             $dao->query("SELECT last_login_ts FROM be_user WHERE email='{$user['email']}'");
             // I know that there is a record in the DB with this email, so no need to check
             $ts_row = $dao->next();
             $last_login = is_null($ts_row['last_login_ts']) ? 'N/A' : date('M jS Y @ g:i A', $ts_row['last_login_ts']);
             $dao->query("UPDATE be_user SET last_login_ts=UNIX_TIMESTAMP() WHERE email='{$user['email']}'");
             $this->getUser()->setAttribute('be_user', array('first_name' => $user['first_name'], 'last_name' => $user['last_name'], 'full_name' => "{$user['first_name']} {$user['last_name']}", 'email' => $user['email'], 'role' => $user['role'], 'phone' => $user['phone'], 'phone_ext' => $user['phone_ext'], 'last_login' => $last_login, 'password' => $user['password']));
             $this->getUser()->setAuthenticated(true);
             $this->getUser()->addCredential($user['role']);
         } else {
             if ($this->getUser()->hasAttribute('be_user')) {
                 $this->getUser()->getAttributeHolder()->remove('be_user');
             }
             $this->getUser()->setAuthenticated(false);
             $this->getUser()->setFlash('login_error', 'Invalid email and/or password!');
         }
         // allows users to go directly to requested page after login
         $uri = $this->getContext()->getRouting()->getCurrentInternalUri(true);
         $this->redirect($uri);
     }
     return sfView::SUCCESS;
 }
 public function createSections(DAO $dao)
 {
     if ($dao->queryOK()) {
         $sections = array();
         $row = $dao->next();
         $count = $row['cnt'];
         $letter = $row[$this->_subcat_field][0];
         $first_section = $last_section = $row[$this->_subcat_field];
         while ($row = $dao->next()) {
             if ($row[$this->_subcat_field][0] == $letter) {
                 // aggregating mode
                 $count += $row['cnt'];
                 $last_section = $row[$this->_subcat_field];
             } else {
                 // section assignment mode
                 $section = $first_section == $last_section ? $first_section : "{$first_section}-{$last_section}";
                 $sections[] = array('section' => $section, 'section_slug' => LWS::slugify($section), 'count' => $count);
                 // update loop values for next section
                 $count = $row['cnt'];
                 $letter = $row[$this->_subcat_field][0];
                 $first_section = $last_section = $row[$this->_subcat_field];
             }
         }
         // end while()
         // add last section aggregated
         $section = $first_section == $last_section ? $first_section : "{$first_section}-{$last_section}";
         $sections[] = array('section' => $section, 'section_slug' => LWS::slugify($section), 'count' => $count);
     } else {
         $sections = NULL;
     }
     return $sections;
 }