コード例 #1
0
ファイル: BasecampController.php プロジェクト: hettema/Stages
 /**
  * Initial connect function to get the user details and also to check the user tocken
  */
 public function connectAction()
 {
     $this->_getSession()->unsSignup();
     $token = $this->getRequest()->getParam('token');
     $host = $this->getRequest()->getParam('host');
     //Load the user object with the bc-token
     $user = App_Main::getModel('stages/user')->load($token, 'bc_auth_token');
     //login and redirect to homepage if the user is already registered
     if ($user->getId()) {
         $user->setSessionUser($user);
         echo Zend_Json::encode(array('redirect' => App_Main::getUrl('')));
         return;
     }
     //Get the Basecamp connect object
     $bcConnect = new Connect_Basecamp($host, $token, 'X', 'xml');
     $userXml = $bcConnect->getMe();
     if (!empty($userXml['body']) && $userXml['status'] == '200 OK') {
         $userArray = App_Main::getHelper('stages')->XMLToArray($userXml['body']);
         $return = array('success' => 1, 'username' => $userArray['user-name'], 'firstname' => $userArray['first-name'], 'lastname' => $userArray['last-name'], 'avatar' => $userArray['avatar-url'], 'token' => $userArray['token']);
         $signUp = App_Main::getModel('core/object');
         $signUp->setMode('bc_token_connect');
         $signUp->setToken($token);
         $signUp->setHost($host);
         $this->_getSession()->setSignup($signUp);
     } else {
         $return = array('success' => 0);
     }
     echo Zend_Json::encode($return);
 }
コード例 #2
0
ファイル: CreateController.php プロジェクト: hettema/Stages
 /**
  * Save the project info
  * 
  * @return type 
  */
 public function saveAction()
 {
     if (!$this->isUserLoggedIn()) {
         echo Zend_Json::encode(array('redirect' => App_Main::getUrl('')));
         return;
     }
     $data = array();
     $data['m_lead'] = $this->getRequestParam('m_lead');
     $data['d_lead'] = $this->getRequestParam('d_lead');
     $bcId = $this->getRequestParam('project_bc_id');
     if ($bcId) {
         $project = $this->_getSession()->getUser()->getProjectById($bcId);
     } else {
         if ($title = $this->getRequestParam('project_title')) {
             $data['title'] = $this->getRequestParam('project_title');
             $project = App_Main::getModel('project/project');
         }
     }
     if ($project && $project->saveProject($data)) {
         $refrshBc = !empty($bcId);
         echo Zend_Json::encode(array('success' => 1, 'project' => $project->prepareDataForJson(true, true, $refrshBc)));
     } else {
         echo Zend_Json::encode(array('success' => 0, 'message' => 'Error saving the project'));
     }
     //return $this->_redirectUrl(App_Main::getUrl('project/index/view'). '?id='. $project->getBcId());
     return false;
 }
コード例 #3
0
ファイル: Translate.php プロジェクト: hettema/Stages
 /**
  * Retrieve translation object
  *
  * @return Zend_Translate_Adapter
  */
 public function initTranslate($forceReload = false)
 {
     if (is_null($this->_translate) || $forceReload) {
         $this->_translate = App_Main::getModel('core/translate_csv', array(App_Main::getBaseDir('locale'), $this->getLocale()));
     }
     return $this->_translate;
 }
コード例 #4
0
ファイル: Frontend.php プロジェクト: hettema/Stages
 public function preDispatch()
 {
     App_Main::getModel('core/url_rewrite')->rewrite();
     //Initialize the display singleton prior to loading layout and initializing controllers
     App_Main::getDesign();
     return $this;
 }
コード例 #5
0
ファイル: DebugController.php プロジェクト: hettema/Stages
 public function email_submitAction()
 {
     $request = $this->getRequest();
     $email_template = $request->getParam('email_template') ? $request->getParam('email_template') : false;
     $websiteId = $request->getParam('website') ? $request->getParam('website') : false;
     $website = App_Main::getModel('core/website');
     if ($websiteId) {
         $website->load($websiteId);
     }
     if (empty($email_template)) {
         echo 'Choose a template file to test';
         return;
     }
     $email = App_Main::getModel('core/email');
     $email->setFromEmail(App_Main::DEFAULT_MAIL_SENDER);
     $email->setFromName(App_Main::DEFAULT_MAIL_SENDER_NAME);
     $email->setType('html');
     $email->setLocale($website->getLocale());
     $email->setTheme($website->getTheme());
     $email->setTemplate($email_template);
     $email->setToEmail('*****@*****.**');
     $email->setToName('recipient name');
     $email->setSubject('Email debugger :: Testing email');
     $email->setTemplateVar(array('name' => 'recipient name', 'email' => '*****@*****.**', 'website_url' => $website->getBaseUrl('web'), 'status' => 'status', 'comments' => 'Notification comments'));
     echo $email->getBody();
 }
コード例 #6
0
ファイル: Collection.php プロジェクト: hettema/Stages
 /**
  * Get the admin users list
  *
  * @return Core_Model_Object 
  */
 public function getResultCollection()
 {
     $query = $this->_getQuery();
     $query->resetQuery();
     //reset the query params set, if any
     $query->queryCondition("c_user.firstname ASC", 'ORDER');
     $query->queryColumn(array("c_user.*"));
     $query->queryTable($this->tbl_user . " AS c_user");
     $read = $this->_getResource()->_getReadAdapter();
     $count = $read->fetchOne($query->prepareCountQuery(), 'count');
     $results = $read->fetchAll($query->prepareQuery());
     $collection = array();
     if (!empty($results)) {
         foreach ($results as $result) {
             $user = App_Main::getModel('admin/user', $result);
             $collection[] = $user;
         }
     }
     $resultColection = new Core_Model_Object();
     $resultColection->setCollection($collection);
     $resultColection->setTotalCount($count);
     if ($this->getFilterValue('page')) {
         $resultColection->setPage($this->getFilterValue('page'));
         $resultColection->setLimit($this->getFilterValue('limit'));
     }
     return $resultColection;
 }
コード例 #7
0
ファイル: Eav.php プロジェクト: hettema/Stages
 /**
  * Load the entity object with the entity id
  * The entity object will loaded form the entity table and the eav will be loaded
  * 
  * @param int $entityId
  * @return pbject entity model 
  */
 public function loadEntity($entityId)
 {
     $entityInfo = $this->getResource()->getEntityInfo($entityId);
     if (!empty($entityInfo)) {
         $entity = App_Main::getModel($entityInfo['entity_model']);
         $entity->load($entityId);
     }
     return $entity;
 }
コード例 #8
0
ファイル: Cron.php プロジェクト: hettema/Stages
 /**
  * Get the cron jobs from databse
  * 
  * @param array $filters
  * @return array 
  */
 public function getJobs($filters = array())
 {
     $query = $this->_getQuery();
     $query->resetQuery();
     $filters['status'] = !isset($filters['status']) ? 1 : $filters['status'];
     $query->queryColumn(array("tbl_job.*"));
     foreach ($filters as $filter => $value) {
         if (empty($value)) {
             continue;
         }
         switch ($filter) {
             case 'name':
                 $query->queryCondition("tbl_job.job_name LIKE '%" . $value . "%'");
                 break;
             case 'status':
                 $query->queryCondition("tbl_job.status =" . $value);
                 break;
             case 'is_scheduled':
                 $query->queryCondition("tbl_job_schedule.scheduled_at > '" . date('Y-m-d H:i:s', time() - 10) . "'");
                 //keeps a 10s escape time
                 $query->queryCondition("tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_PENDING . "'");
                 break;
             case 'is_schedule_active':
                 $query->queryCondition("tbl_job_schedule.scheduled_at > '" . now() . "'");
                 $query->queryCondition("(tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_PENDING . "' || tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_RUNNING . "')");
                 break;
             case 'is_finished':
                 $query->queryCondition("tbl_job_schedule.scheduled_at < '" . now() . "'");
                 $query->queryCondition("tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_SUCCESS . "'");
                 break;
             case 'is_running':
                 $query->queryCondition("tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_RUNNING . "'");
                 break;
             case 'is_error':
                 $query->queryCondition("tbl_job_schedule.status ='" . Cron_Model_Cron::STATUS_ERROR . "'");
                 break;
         }
     }
     $query->queryCondition("tbl_job.job_id", "GROUP");
     $query->queryCondition("tbl_job_schedule.scheduled_at ASC", "ORDER");
     $query->queryTable($this->tbl_cron_job . " AS tbl_job");
     $query->queryTable("LEFT JOIN " . $this->tbl_cron_job_schedule . " AS tbl_job_schedule ON tbl_job_schedule.job_id = tbl_job.job_id");
     $results = $this->_getReadAdapter()->fetchAll($query->prepareQuery());
     $colection = array();
     if (empty($results)) {
         return $colection;
     }
     foreach ($results as $result) {
         $result['schedules'] = $this->_getReadAdapter()->fetchAll("SELECT schedule_id, job_code, status, messages, created_at, scheduled_at, executed_at, finished_at FROM " . $this->tbl_cron_job_schedule . " WHERE job_id=" . $result['job_id'] . " AND scheduled_at >= '" . now() . "' ORDER BY scheduled_at ASC");
         $colection[] = App_Main::getModel('cron/job', $result);
     }
     return $colection;
 }
コード例 #9
0
ファイル: Abstract.php プロジェクト: hettema/Stages
 /**
  * Get the core email object
  * 
  * @return Core_Model_Email 
  */
 protected function _getMail()
 {
     $email = App_Main::getModel('core/email');
     $email->setType('html');
     $email->setFromEmail($this->getWebsite()->getConfig('mail-default-sender-email'));
     $email->setFromName($this->getWebsite()->getConfig('mail-default-sender-name'));
     $email->setReturnPath($this->getWebsite()->getConfig('mail-default-sender-email'));
     $email->setBcc($this->getWebsite()->getConfig('mail-default-bcc-email'));
     $email->setLocale($this->getWebsite()->getLocale());
     $email->setTheme($this->getWebsite()->getTheme());
     return $email;
 }
コード例 #10
0
ファイル: ConfigController.php プロジェクト: hettema/Stages
 /**
  * Add a new website
  * @return type 
  */
 public function website_addAction()
 {
     $websiteCode = $this->getRequest()->getParam('website_code');
     $website = App_Main::getModel('core/website');
     if (!$website->validateWebsiteCode($websiteCode)) {
         App_Main::getSession()->addError('The website code you have specified is invalid or is already existing. Please try a new one code');
         $this->_redirect('backend/config/websites');
         return;
     }
     $website->setData('code', $websiteCode);
     $website->setData('name', $this->getRequest()->getParam('website_name'));
     $website->save();
     $this->_redirect('backend/config/index', array('website' => $website->getId()));
 }
コード例 #11
0
ファイル: EavController.php プロジェクト: hettema/Stages
 /**
  * Check for unique attribute values
  * Queried over ajax
  */
 public function check_uniqueAction()
 {
     $data = $this->getRequest()->getParam('check_data');
     if (!empty($data)) {
         $eavEdit = App_Main::getModel('backend/eav_edit');
         $response = $eavEdit->checkUniqueXmlEavData($data);
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->getResponse()->setHeader('Content-Type', 'text/xml');
         $this->getResponse()->setBody('<response_root>' . $response . '</response_root>');
     } else {
         //code for html display..
     }
 }
コード例 #12
0
ファイル: Email.php プロジェクト: hettema/Stages
 /**
  * Prepare the body of the email
  * If the email is configured to be an HTML email the block outbupt is generated 
  * in the same way it is done for loading the layout
  * 
  * @return string 
  */
 public function getBody()
 {
     $body = $this->getData('body');
     if (empty($body) && $this->getTemplate()) {
         $this->_block = App_Main::getModel('core/layout')->createBlock('core/email_template', 'email')->setArea($this->getArea())->setTheme($this->getTheme())->setLocale($this->getLocale())->setTemplate($this->getTemplate());
         foreach ($this->getTemplateVars() as $var => $value) {
             $this->_block->assign($var, $value);
             $this->_block->setData($var, $value);
         }
         $this->_block->assign('_type', strtolower($this->getType()))->assign('_section', 'body');
         $body = $this->_block->toHtml();
     }
     return $body;
 }
コード例 #13
0
ファイル: Todolist.php プロジェクト: hettema/Stages
 /**
  * Get the todos for the todolist from database
  * 
  * @param Core_Model_Object $object
  * @return array Project_Model_Todo 
  */
 public function getTodos(Core_Model_Object $object)
 {
     if (!$object->getBcId()) {
         return array();
     }
     $result = $this->_getReadAdapter()->fetchAll("SELECT * FROM " . $this->tbl_todo . " WHERE todolist_id=" . $object->getBcId());
     if (!$result) {
         return array();
     }
     $todos = array();
     foreach ($result as $data) {
         $todos[] = App_Main::getModel('project/todo', $data);
     }
     return $todos;
 }
コード例 #14
0
ファイル: Time.php プロジェクト: hettema/Stages
 /**
 * Get time-entries for a project created already in Basecamp
 * Save the time entry info if it is not loaded into database
 * - description
 * - project_id
 * - todo_id
 * - person_id
 * - bc_date
 * - hours
   - bc_id
 * 
 * @param integer $projectId basecamp project id
 * @param bool $fromBc
 * @return array milestones Project_Model_Time
 */
 public function loadTimeFromBc($entityId, $type = 'project', $page = 0, $fromBc = true)
 {
     switch ($type) {
         case 'project':
             //load time for project
             $respXml = $this->getBcConnect()->getTimeEntriesForProject($entityId, $page);
             break;
         case 'todo':
             //load time for todo
             $respXml = $this->getBcConnect()->getTimeEntriesForTodoItem($entityId, $page);
             break;
     }
     if (empty($respXml['body'])) {
         return array();
     }
     if ($respXml['pages'] < $page) {
         return array();
     }
     //parse the response body into array
     $tArray = $this->_getHelper()->XMLToArray(simplexml_load_string($respXml['body']));
     $timeEntries = array();
     if (!empty($tArray['time-entry'])) {
         $tArray = !empty($tArray['time-entry']['id']) ? array($tArray['time-entry']) : $tArray['time-entry'];
         foreach ($tArray as $data) {
             if (empty($data['id'])) {
                 continue;
             }
             $timeEntry = App_Main::getModel('project/time')->load($data['id'], 'bc_id');
             $timeEntry->setDescription(substr($data['description'], 0, 254));
             $timeEntry->setProjectId($data['project-id']);
             $timeEntry->setTodoId($data['todo-item-id']);
             $timeEntry->setPersonId($data['person-id']);
             $timeEntry->setBcDate($data['date']);
             $timeEntry->setHours($data['hours']);
             $timeEntry->setBcId($data['id']);
             if (!$timeEntry->getAddedDate()) {
                 $timeEntry->setAddedDate(now());
             }
             if (!$timeEntry->getId() || $timeEntry->getOrigData('todo_id') != $timeEntry->getTodoId() || $timeEntry->getOrigData('person_id') != $timeEntry->getPersonId() || $timeEntry->getOrigData('bc_date') != $timeEntry->getBcDate() || $timeEntry->getOrigData('hours') != $timeEntry->{$timeEntry}->getHours()) {
                 //save time entry data
                 $timeEntry->setUpdatedDate(now());
                 $timeEntry->save();
             }
             $timeEntries[] = $timeEntry;
         }
     }
     return $timeEntries;
 }
コード例 #15
0
ファイル: Todo.php プロジェクト: hettema/Stages
 /**
  * Get todos for a project created already in Basecamp
  * 
  * @param integer $todolistId basecamp project id
  * @param bool $fromBc
  * @return array milestones Project_Model_Todo
  */
 public function loadTodosFromBc($todolistId, $projectId = null)
 {
     $respXml = $this->getBcConnect()->getTodoItemsForList($todolistId);
     if (empty($respXml['body'])) {
         return array();
     }
     $tArray = $this->_getHelper()->XMLToArray(simplexml_load_string($respXml['body']));
     $todos = array();
     if (!empty($tArray['todo-item'])) {
         $tArray = !empty($tArray['todo-item']['id']) ? array($tArray['todo-item']) : $tArray['todo-item'];
         foreach ($tArray as $data) {
             if (empty($data['id'])) {
                 continue;
             }
             $todo = App_Main::getModel('project/todo')->load($data['id'], 'bc_id');
             $status = empty($data['completed']) || $data['completed'] == 'false' ? 0 : 1;
             $todo->setTitle(substr($data['content'], 0, 254));
             $todo->setTodolistId($data['todo-list-id']);
             $todo->setBcId($data['id']);
             $todo->setBcStatus($status);
             $todo->setBcAddedDate(date('Y-m-d H:i:s', strtotime($data['created-on'])));
             $todo->setBcUpdatedDate(date('Y-m-d H:i:s', strtotime($data['updated-at'])));
             $todo->setCommentCount($data['comments-count']);
             if (!$todo->getAddedDate()) {
                 $todo->setAddedDate(now());
             }
             if (!$todo->getId() || $todo->getOrigData('todolist_id') != $todo->getTodolistId() || $todo->getOrigData('bc_status') != $todo->getBcStatus() || $todo->getOrigData('comment_count') != $todo->getCommentCount() || $todo->getOrigData('title') != $todo->getTitle()) {
                 //save todo data
                 $todo->setUpdatedDate(now());
                 $todo->save();
             }
             $todos[] = $todo;
         }
     }
     return $todos;
 }
コード例 #16
0
ファイル: Session.php プロジェクト: hettema/Stages
 /**
  * Try to login user in admin
  *
  * @param  string $username
  * @param  string $password
  * @param  Core_Controller_Request_Http $request
  * @return Admin_Model_User|null
  */
 public function login($username, $password, $request = null)
 {
     if (empty($username) || empty($password)) {
         return;
     }
     try {
         /* @var $user Admin_Model_User */
         $user = App_Main::getModel('admin/user');
         $user->login($username, $password);
         if ($user->getId()) {
             $session = App_Main::getSingleton('admin/session');
             $session->setIsFirstVisit(true);
             $session->setUser($user);
         } else {
             throw App_Main::exception('Core', 'Invalid Username or Password.');
         }
     } catch (Core_Exception $e) {
         if ($request && !$request->getParam('messageSent')) {
             App_Main::getSingleton('core/session')->addError($e->getMessage());
             $request->setParam('messageSent', true);
         }
     }
     return $user;
 }
コード例 #17
0
ファイル: Edit.php プロジェクト: hettema/Stages
 /**
  * Saves the eav data speecific to the entity or entity type id specified
  * 
  * @param string $xmlData
  * @param int $entityTypeId
  * @return Core_Model_Abstract
  */
 public function submitXmlEavData($xmlData, $entityTypeId = null)
 {
     $xml = new SimpleXMLElement($xmlData);
     $entityNode = $xml->entity;
     if ($entityNode['entityTypeId']) {
         $entityTypeId = (string) $entity['entityTypeId'];
     }
     //initiate the model for the entity and update the submitted entity
     if (!empty($entityNode['entity_id'])) {
         $entityId = intval((string) $entityNode['entity_id']);
         $entityId = is_int($entityId) ? $entityId : null;
         if (!empty($entityId)) {
             $entity = $this->loadEntity($entityId);
         }
     }
     //initiate the model for the entity type and save it as a new entity
     if ((empty($entity) || !$entity instanceof Core_Model_Abstract) && !empty($entityTypeId)) {
         $entityModel = $this->getResource()->getEntityModel($entityTypeId);
         if (!empty($entityModel)) {
             $entity = App_Main::getModel($entityModel);
             $entity->setEntityTypeId($entityTypeId);
         }
     }
     if (empty($entity)) {
         App_Main::getSession()->addError('Unable to load the entity model for the submitted data.');
         return false;
     }
     //Assign the attribute values into the entity object prior to saving
     foreach ($entityNode->children() as $childNode) {
         $backend = (string) $childNode['backendType'];
         $attributeCode = (string) $childNode->getName();
         $attributeId = (string) $childNode['attributeId'];
         $entity->setData($attributeCode, (string) $childNode);
     }
     $entity->setUpdatedAt(now());
     $entity->save();
     return $entity;
 }
コード例 #18
0
ファイル: UserController.php プロジェクト: hettema/Stages
 /**
  * Delete selected admin user
  */
 public function deleteAction()
 {
     $request = $this->getRequest();
     if (!$request->getParam('id')) {
         return false;
     }
     $user = App_Main::getModel('admin/user', array('user_id' => $request->getParam('id')));
     $user->delete();
     $this->_redirect('admin/user');
 }
コード例 #19
0
ファイル: Website.php プロジェクト: hettema/Stages
 /**
  * Get the default website
  *
  * @return Core_Model_Website 
  */
 public function getDefaultWebsite()
 {
     $result = $this->_getReadAdapter()->fetchRow("SELECT * FROM " . $this->tbl_website . " WHERE is_default = 1 LIMIT 1");
     return App_Main::getModel('core/website', $result);
 }
コード例 #20
0
ファイル: Milestone.php プロジェクト: hettema/Stages
 /**
  * Create todolist for the milestone
  * 
  * @param string $title
  * @return Project_Model_Todolist 
  */
 public function createTodolist($title)
 {
     $todolist = App_Main::getModel('project/todolist');
     $todolist->setTitle($title);
     $todolist->setProjectId($this->getProjectId());
     $todolist->setMilestoneId($this->getBcId());
     $todolist->setDescription('');
     return $todolist->saveTodolist();
 }
コード例 #21
0
ファイル: Abstract.php プロジェクト: hettema/Stages
 /**
  *
  * @return Core_Model_Url 
  */
 protected function _getUrlModel()
 {
     return App_Main::getModel($this->_getUrlModelClass());
 }
コード例 #22
0
ファイル: List.php プロジェクト: hettema/Stages
 /**
  * Get all the configured cron jobs
  * 
  * @return array 
  */
 public function getCronJobs()
 {
     App_Main::getModel('cron/cron')->initCronJobs();
     return App_Main::getModel('cron/cron')->getJobs();
 }
コード例 #23
0
ファイル: IndexController.php プロジェクト: hettema/Stages
 /**
  * Tmp function to load the time-entries
  */
 public function load_time_entryAction()
 {
     $result = App_Main::getModel('project/time')->loadTimeFromBc(5223184);
 }
コード例 #24
0
ファイル: Project.php プロジェクト: hettema/Stages
 /**
  * Save a milestone and create/update it in Basecamp
  * 
  * @param string $title  Milestone title
  * @param string $date  Milestone date
  * @param int $user  Milestone responsible user
  * @param string $type  Milestone type (M|D)
  * @param int $bcId  milestone Basecamp id
  * @return type 
  */
 public function saveMilestone($title, $date, $user, $type, $bcId = null)
 {
     $mode = 'edit';
     if (!empty($bcId)) {
         $milestone = $this->getMilestoneById($bcId);
     }
     if (empty($milestone)) {
         $milestone = App_Main::getModel('project/milestone');
         $milestone->setProjectId($this->getBcId());
         $mode = 'add';
     }
     $milestone = $milestone->saveMilestone($title, $this->_getHelper()->formatDateFromJs($date), $user, $type);
     if ($milestone && $mode == 'add') {
         $this->_milestones[] = $milestone;
     }
     return $milestone;
 }
コード例 #25
0
ファイル: User.php プロジェクト: hettema/Stages
 /**
  * Send email with new user password
  *
  * @return Admin_Model_User
  */
 public function sendNewPasswordEmail()
 {
     App_Main::getModel('core/email_template')->setDesignConfig(array('area' => 'backend'))->sendTransactional(self::FORGOT_EMAIL_TEMPLATE, self::FORGOT_EMAIL_IDENTITY, $this->getEmail(), $this->getName(), array('user' => $this, 'password' => $this->getPlainPassword()));
     return $this;
 }
コード例 #26
0
ファイル: Collection.php プロジェクト: hettema/Stages
 /**
  * Retrive the visitors list filterd
  * 
  * @return Core_Model_Object 
  */
 public function getResultCollection()
 {
     $query = $this->_getQuery();
     $query->resetQuery();
     $query->queryColumn(array("visitor.visitor_id", "count(DISTINCT(visitor.visitor_id)) AS visits", "visitor_info.http_referer AS referer", "visitor_info.remote_addr AS ip_address", "UNIX_TIMESTAMP(MIN(visitor.first_visit_at)) AS first_visit_ts", "count(url.url_id) AS total_visits", "UNIX_TIMESTAMP(MAX(visitor.last_visit_at)) AS last_visit_ts", "TIMEDIFF(visitor.last_visit_at,visitor.first_visit_at) AS time_on_site", "visitor_info.http_user_agent"));
     foreach ($this->filters as $filter => $value) {
         if (empty($value)) {
             continue;
         }
         switch ($filter) {
             case 'date_from':
                 $query->queryCondition("visitor.first_visit_at >= '" . $value . "' ");
                 break;
             case 'date_to':
                 $query->queryCondition("visitor.first_visit_at <= '" . $value . " 23:59:59' ");
                 break;
             case 'no_robots':
                 $query->queryCondition("(visitor_info.http_user_agent NOT LIKE '%googlebot%' AND visitor_info.http_user_agent NOT LIKE '%AdsBot-Google%' AND visitor_info.http_user_agent NOT LIKE '%bingbot%' AND visitor_info.http_user_agent NOT LIKE '%Yahoo! Slurp%' AND visitor_info.http_user_agent NOT LIKE '%baiduspider%' AND visitor_info.http_user_agent NOT LIKE '%ia_archiver%' AND visitor_info.http_user_agent NOT LIKE '%Twiceler%' AND visitor_info.http_user_agent NOT LIKE '%pingdom.com_bot%' AND visitor_info.http_user_agent NOT LIKE '%Toata%' AND  visitor_info.http_user_agent NOT LIKE '%www.seoprofiler.com%') ");
                 break;
             case 'min_page_visit':
                 $query->queryCondition("count(url.url_id) >= '" . $value . "' ", 'HAVING');
                 break;
             case 'browser':
                 $query->queryCondition("visitor_info.http_user_agent LIKE '%" . $value . "%' ");
                 break;
             case 'os':
                 $query->queryCondition("visitor_info.http_user_agent LIKE '%" . $value . "%' ");
                 break;
             case 'url':
                 $query->queryCondition("url_info.url LIKE '%" . $value . "%' ");
                 break;
             case 'redirect_source':
                 $query->queryCondition("visitor_info.http_referer LIKE '%" . $value . "%' ");
                 break;
             case 'hide_me':
                 $query->queryCondition("visitor_info.remote_addr != '" . ip2long($_SERVER['REMOTE_ADDR']) . "' ");
                 break;
             case 'hide_proxy':
                 $query->queryCondition("(visitor_info.remote_addr != '" . ip2long('10.206.59.239') . "' AND visitor_info.remote_addr != '" . ip2long('174.129.106.25') . "')");
                 break;
             case 'hide_proxy_ping':
                 $query->queryCondition("url_info.url NOT LIKE '%test.html%' ");
                 break;
             case 'show_fb_redirects':
                 $query->queryCondition("visitor_info.http_referer LIKE '%facebook.com%' ");
                 break;
             case 'show_blogger_redirects':
                 $query->queryCondition("url_info.url LIKE '%?b=%' ");
                 break;
             case 'page':
                 if (!empty($this->filters['limit'])) {
                     $query->queryCondition($this->filters['limit'] * ($value - 1) . "," . $this->filters['limit'], 'LIMIT');
                 }
                 break;
             case 'group_by':
                 switch (strtolower($this->filters['group_by'])) {
                     case 'ip':
                         $query->queryCondition('visitor_info.remote_addr', 'GROUP');
                         break;
                     case 'visitor_id':
                     default:
                         $query->queryCondition('visitor.visitor_id', 'GROUP');
                         break;
                 }
                 break;
             case 'order_by':
                 switch (strtolower($this->filters['order_by'])) {
                     case 'visitor_id':
                         $query->queryCondition("visitor.visitor_id " . $this->filters['order'], 'ORDER');
                         break;
                     case 'totalvisit':
                         $query->queryCondition("count(url.url_id) " . $this->filters['order'], 'ORDER');
                         break;
                     case 'httpuseragent':
                         $query->queryCondition("visitor_info.http_user_agent " . $this->filters['order'], 'ORDER');
                         break;
                     case 'lastvisit':
                         $query->queryCondition("visitor.last_visit_at " . $this->filters['order'], 'ORDER');
                         break;
                     case 'firstvisit':
                         $query->queryCondition("visitor.first_visit_at " . $this->filters['order'], 'ORDER');
                         break;
                     case 'timeonsite':
                         $query->queryCondition("TIMEDIFF(visitor.last_visit_at,visitor.first_visit_at) " . $this->filters['order'], 'ORDER');
                         break;
                 }
                 break;
         }
     }
     $query->queryTable($this->tbl_visitor . " AS visitor");
     $query->queryTable("LEFT JOIN " . $this->tbl_visitor_info . " AS visitor_info USING(visitor_id)");
     $query->queryTable("LEFT JOIN " . $this->tbl_url . " AS url ON url.visitor_id = visitor.visitor_id");
     $query->queryTable("LEFT JOIN " . $this->tbl_url_info . " AS url_info ON url_info.url_id = url.url_id");
     $read = $this->_getResource()->_getReadAdapter();
     $count = $read->fetchOne($query->prepareCountQuery(), 'count');
     $results = $read->fetchAll($query->prepareQuery());
     $collection = array();
     if (!empty($results)) {
         foreach ($results as $result) {
             $collection[] = App_Main::getModel('core/object', $result);
         }
     }
     $resultCollection = new Core_Model_Object();
     $resultCollection->setCollection($collection);
     $resultCollection->setTotalCount($count);
     $resultCollection->setFilters(App_Main::getModel('core/object', $this->filters));
     if ($this->getFilterValue('page')) {
         $resultCollection->setPage($this->getFilterValue('page'));
         $resultCollection->setLimit($this->getFilterValue('limit'));
     }
     return $resultCollection;
 }
コード例 #27
0
ファイル: IndexController.php プロジェクト: hettema/Stages
 /**
  * Submit the user profile
  */
 public function submit_user_profileAction()
 {
     $request = $this->getRequest();
     $userId = $request->getParam('user_id');
     if (empty($userId)) {
         $this->_redirect('');
     }
     $user = App_Main::getModel('admin/user');
     $user->setUserId($userId);
     $user->setFirstname($request->getParam('firstname'));
     $user->setLastname($request->getParam('lastname'));
     $user->setEmail($request->getParam('email'));
     if ($request->getParam('change_password') && $request->getParam('new_password') && $request->getParam('new_password') != 'new_password') {
         $user->setNewPassword($request->getParam('new_password'));
         App_Main::getSession()->addSuccess('User account password changed to ' . $user->getNewPassword());
     }
     $user->save();
     $this->_redirect('admin/index/edit_profile');
     App_Main::getSession()->addSuccess('User account profile updated');
 }
コード例 #28
0
ファイル: Session.php プロジェクト: hettema/Stages
 /**
  * Retrieve messages from session
  *
  * @param   bool $clear
  * @return  Core_Model_Message_Collection
  */
 public function getMessages($clear = false)
 {
     if (!$this->getData('messages')) {
         $this->setMessages(App_Main::getModel('core/message_collection'));
     }
     if ($clear) {
         $messages = clone $this->getData('messages');
         $this->getData('messages')->clear();
         return $messages;
     }
     return $this->getData('messages');
 }
コード例 #29
0
ファイル: Cron.php プロジェクト: hettema/Stages
 /**
  * Process the cheduled cron jobs and execute them according to the current time 
  * @todo make it possilbbe to specify the buffer time and then process the job so that the timings are exactly correct
  * 
  * @return bool 
  */
 public function dispatch()
 {
     $this->getResource()->markMissedJobs(date('Y-m-d H:i:s', time() - 60 * self::SCHEDULE_AHEAD_FOR));
     $dispatchStartTime = now();
     $jobs = $this->getResource()->getScheduledCronJobs();
     foreach ($jobs as $job) {
         $schedules = $job->getSchedules();
         $schedule = !empty($schedules) ? array_shift($schedules) : false;
         if (!$schedule) {
             continue;
         }
         if (time() - strtotime($dispatchStartTime) > self::MAX_RUN_INTERVAL) {
             return;
         }
         //exit if the current running time exeeds maximum
         $scheduleId = $schedule['schedule_id'];
         $timeDiff = strtotime($schedule['scheduled_at']) - time();
         if ($timeDiff > self::MAX_RUN_INTERVAL) {
             return;
         }
         //return if the time interval is greater than the max run time
         if ($timeDiff > 10) {
             $this->getResource()->updateJobStatus($scheduleId, self::STATUS_WAITING);
             sleep($timeDiff);
         }
         $this->getResource()->updateJobStatus($scheduleId, self::STATUS_RUNNING);
         $modelInstance = App_Main::getModel($job->getModule());
         if ($job->getAction()) {
             $action = $job->getAction();
             try {
                 $modelInstance->{$action}();
             } catch (Exception $e) {
                 $this->getResource()->updateJobStatus($scheduleId, self::STATUS_ERROR, null, $e->__toString());
             }
         }
         $this->getResource()->updateJobStatus($scheduleId, self::STATUS_SUCCESS);
     }
     $this->getResource()->markMissedJobs($dispatchStartTime);
     return true;
 }
コード例 #30
0
ファイル: UserController.php プロジェクト: hettema/Stages
 /**
  * Reset the user passowrd with a random password generated by the system 
  * and email it to the user email
  * @todo change the method by keeping one validation email before generating the passord automated password
  * @return type 
  */
 public function forgot_passwordAction()
 {
     $user = App_Main::getModel('stages/user')->load($this->getRequest()->getParam('login_name'), 'email');
     if ($user->getId()) {
         $user->resetPassword();
         $this->_getSession()->addSuccess('Password sent to your registered email address');
     } else {
         $this->_getSession()->addError('Unknown email address');
     }
     return $this->_redirect('');
 }