예제 #1
0
 public function onDisplayLogPage()
 {
     // get all items
     #$logs = $logModel->getAll();
     //Create an instance of LogTable
     $logTable = new LogTable();
     $logTable->prepare_items();
     // parse errors - tmp var $items required for php 5.4
     $items = $logTable->items;
     foreach ($items as &$item) {
         $item['errors'] = $this->parseErrors($item);
     }
     $logTable->items = $items;
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'logTable' => $logTable, 'tableSize' => $this->getTableSize(), 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-log');
     $this->display('log_page', $aData);
 }
 function approveChallenge($completedid, $pointsAwarded, &$code, $dontLog = false)
 {
     // changes completed record to approved, awards points, logs the completion
     $cc = $this->getRowObject();
     $ct = new ChallengeTable($this->db);
     $challenge = $ct->getRowObject();
     require_once PATH_CORE . '/classes/user.class.php';
     $uit = new UserInfoTable($this->db);
     $ui = $uit->getRowObject();
     $ut = new UserTable($this->db);
     $u = $ut->getRowObject();
     if (!($cc->load($completedid) && $challenge->load($cc->challengeid) && $ui->load($cc->userid) && $u->load($cc->userid))) {
         $code .= 'Couldnt find submission matching id ' . $completedid . ' or challenge matching id ' . $cc->challengeid . ' or user matching id ' . $cc->userid;
         return false;
     }
     if ($challenge->remainingCompletions < 1 && $challenge->initialCompletions != 0) {
         $code .= 'This challenge has no remaining global completions';
         return false;
     }
     // get total user completions of this challenges
     $q = $this->db->query("SELECT SQL_CALC_FOUND_ROWS * \n\t\t\tFROM ChallengesCompleted WHERE challengeid={$cc->challengeid} \n\t\t\t\t\t\t\t\t\t\tAND userid={$cc->userid} \n\t\t\t\t\t\t\t\t\t\tAND status='awarded'\n\t\t\t\t\t\t\t\t\t\tAND dateSubmitted>=DATE_SUB(CURDATE(),INTERVAL 1 DAY); \n\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t");
     $userCompletionsLast24Hours = $this->db->countQ($q);
     $q = $this->db->query("SELECT SQL_CALC_FOUND_ROWS * \n\t\t\tFROM ChallengesCompleted WHERE challengeid={$cc->challengeid} \n\t\t\t\t\t\t\t\t\t\tAND userid={$cc->userid} \n\t\t\t\t\t\t\t\t\t\tAND status='awarded'");
     $userCompletions = $this->db->countQ($q);
     $code .= 'User completed this challenge ' . $userCompletions . ' times total, ' . $userCompletionsLast24Hours . ' times today...';
     if ($userCompletions >= $challenge->maxUserCompletions && $challenge->maxUserCompletions != 0) {
         $code .= 'User not allowed to complete this challenge again';
         return false;
     }
     if ($userCompletionsLast24Hours >= $challenge->maxUserCompletionsPerDay && $challenge->maxUserCompletionsPerDay != 0) {
         $code .= 'User not allowed to complete this challenge again today';
         return false;
     }
     if ($userCompletions == 0) {
         $ui->cachedChallengesCompleted++;
         $ui->update();
     }
     if (!$dontLog) {
         require_once PATH_CORE . '/classes/log.class.php';
         $lt = new LogTable($this->db);
         $log = $lt->getRowObject();
         $log->action = 'completedChallenge';
         $log->userid1 = $cc->userid;
         $log->itemid = $completedid;
         $log->dateCreated = date('Y-m-d H:i:s', time());
         $log->insert();
         $cc->logid = $log->id;
         // for consistency, link with the log entry
     }
     $cc->status = 'awarded';
     $cc->pointsAwarded = $pointsAwarded;
     $cc->dateAwarded = date('Y-m-d H:i:s', time());
     $cc->update();
     $challenge->remainingCompletions--;
     $challenge->update();
     $u->cachedPointTotal += $pointsAwarded;
     $u->update();
     $code .= 'Challenge completion approved.';
     return true;
 }
예제 #3
0
 /**
  * Adds a new admin or superadmin to the system. Optionally it can send a welcome email.
  */
 public function addAction()
 {
     $form = new ViMbAdmin_Form_Admin_Edit();
     $form->removeElement('salt');
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $adminModel = new Admin();
         $adminModel->fromArray($form->getValues());
         $adminModel->setPassword($form->getValue('password'), $this->_options['securitysalt'], false);
         $adminModel->save();
         LogTable::log('ADMIN_ADD', "Added new " . ($adminModel['super'] ? 'super ' : '') . "admin {$adminModel['username']}", $this->getAdmin());
         if ($form->getValue('welcome_email')) {
             try {
                 $mailer = new Zend_Mail();
                 $mailer->setSubject(_('ViMbAdmin :: Your New Administrator Account'));
                 $mailer->addTo($adminModel->username);
                 $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
                 $this->view->username = $adminModel->username;
                 $this->view->password = $form->getValue('password');
                 $mailer->setBodyText($this->view->render('admin/email/new_admin.phtml'));
                 $mailer->send();
             } catch (Exception $e) {
                 $this->getLogger()->debug($e->getTraceAsString());
                 $this->addMessage(_('Could not send welcome email'), ViMbAdmin_Message::ALERT);
             }
         }
         $this->addMessage(_('You have successfully added a new administrator to the system.'), ViMbAdmin_Message::SUCCESS);
         $this->_helper->viewRenderer->setNoRender(true);
         return print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->form = $form;
 }
예제 #4
0
 /**
  * Action FOR ADMINS AND SUPERADMINS to change the password of a mailbox.
  */
 public function passwordAction()
 {
     if (!$this->_mailbox) {
         $this->_helper->viewRenderer->setNoRender(true);
         $this->addMessage(_('No mailbox id passed.'), ViMbAdmin_Message::ERROR);
         return print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->mailbox = $this->_mailbox;
     $form = new ViMbAdmin_Form_Admin_Password();
     if ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $plainPassword = $form->getValue('password');
         $this->_mailbox->hashPassword($this->_options['defaults']['mailbox']['password_scheme'], $plainPassword, $this->_options['defaults']['mailbox']['password_hash']);
         $this->_mailbox->save();
         if ($form->getValue('email')) {
             $mailer = new Zend_Mail();
             $mailer->setSubject(_('New Password for ' . $this->_mailbox['username']));
             $mailer->setFrom($this->_options['server']['email']['address'], $this->_options['server']['email']['name']);
             $mailer->addTo($this->_mailbox['username'], $this->_mailbox['name']);
             $this->view->newPassword = $form->getValue('password');
             $mailer->setBodyText($this->view->render('mailbox/email/change_password.phtml'));
             try {
                 $mailer->send();
             } catch (Zend_Mail_Exception $vException) {
                 $this->getLogger()->debug($vException->getTraceAsString());
                 $this->addMessage(_('Could not send email.'), ViMbAdmin_Message::ALERT);
                 return false;
             }
         }
         LogTable::log('MAILBOX_PW_CHANGE', "Changed password for {$this->_mailbox['username']}", $this->getAdmin(), $this->_mailbox['domain']);
         $this->_helper->viewRenderer->setNoRender(true);
         $this->addMessage(_('Password has been sucessfully changed.'), ViMbAdmin_Message::SUCCESS);
         print $this->view->render('close_colorbox_reload_parent.phtml');
     }
     $this->view->form = $form;
 }
 $manageObj->addColumn("Newswire", "feedid", "INT(11) default 0");
 if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'content.class.php')) {
     require_once PATH_CORE . '/classes/content.class.php';
     ContentTable::createTable($manageObj);
 }
 if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'comments.class.php')) {
     require_once PATH_CORE . '/classes/comments.class.php';
     CommentTable::createTable($manageObj);
 }
 if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'cron.class.php')) {
     require_once PATH_CORE . '/classes/cron.class.php';
     CronJobsTable::createTable($manageObj);
 }
 if ($manageObj->modifyLibrary(PATH_CORE . '/classes/', 'log.class.php')) {
     require_once PATH_CORE . '/classes/log.class.php';
     LogTable::createTable($manageObj);
     LogExtraTable::createTable($manageObj);
 }
 // Resources for Folders and Links
 $manageObj->addTable("Folders", "id", "INT(11) unsigned NOT NULL auto_increment", "MyISAM");
 $manageObj->addColumn("Folders", "folderid", "INT(11) NOT NULL default 0");
 $manageObj->addColumn("Folders", "uid", "INT(11) NOT NULL default 0");
 $manageObj->addColumn("Folders", "title", "VARCHAR(50) default ''");
 $manageObj->addTable("FolderLinks", "id", "INT(11) unsigned NOT NULL auto_increment", "MyISAM");
 $manageObj->addColumn("FolderLinks", "linkid", "INT(11) NOT NULL default 0");
 $manageObj->addColumn("FolderLinks", "folderid", "INT(11) NOT NULL default 0");
 $manageObj->addColumn("FolderLinks", "title", "VARCHAR(255) default ''");
 $manageObj->addColumn("FolderLinks", "url", "varchar(255) default ''");
 $manageObj->addColumn("FolderLinks", "notes", "VARCHAR(255) default ''");
 $manageObj->addColumn('FolderLinks', 'linkType', "enum ('link','product')");
 $manageObj->addColumn('FolderLinks', 'imageUrl', "VARCHAR(255) default '';");
예제 #6
0
 /**
  * Purges a mailbox, removes all the related entries from the other tables.
  * Prints 'ok' on success or 'ko' otherwise to stdout.
  */
 public function ajaxPurgeAction()
 {
     $this->authorise(true);
     Doctrine_Query::create()->delete()->from('Mailbox')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('Log')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('DomainAdmin')->where('domain = ?', $this->_domain['domain'])->execute();
     Doctrine_Query::create()->delete()->from('Alias')->where('domain = ?', $this->_domain['domain'])->execute();
     $this->_domain->delete();
     LogTable::log('DOMAIN_PURGE', "Purged {$this->_domain['domain']}", $this->getAdmin(), null);
     print 'ok';
 }
 function fetchFeedScoreLog($filter_userid, $currentPage = 1, $rowsPerPage = 10)
 {
     // userid is passed in because there is no session when refreshed with Ajax
     require_once PATH_CORE . '/classes/log.class.php';
     $lt = new LogTable($this->db);
     $logaction = $lt->getRowObject();
     $startRow = ($currentPage - 1) * $rowsPerPage;
     // replace rows per page
     $actionIdList = $this->db->query("SELECT SQL_CALC_FOUND_ROWS\t\n\t\t\t\t\tChallengesCompleted.id AS id,fbId,dateSubmitted,\n\t\t\t\t\tshortName, logid, pointsAwarded\n\t\t\tFROM ChallengesCompleted,UserInfo,Challenges \n\t\t\tWHERE ChallengesCompleted.status='awarded' \n\t\t\t\tAND ChallengesCompleted.userid=UserInfo.userid\n\t\t\t\tAND ChallengesCompleted.challengeid = Challenges.id \n\t\t\t\tAND UserInfo.userid={$filter_userid}\t\t\t\t\n\t\t\tORDER BY dateSubmitted DESC " . ($rowsPerPage ? "LIMIT {$startRow}," . $rowsPerPage . ";" : ";"));
     // $this->page->rowsPerPage
     $rowTotal = $this->templateObj->db->countFoundRows();
     if ($this->db->countQ($actionIdList) > 0) {
         while ($data = $this->db->readQ($actionIdList)) {
             /*$debugcomment .= "<div class='hidden'> logid=$data->logid, ccid=$data->id </div>";
             		$code .= "<li id='actionFeedItem'>$debugcomment</li>"; // hack for now 
             		*/
             $showCompletedChallengeEntry = true;
             if ($data->logid) {
                 if ($logaction->load($data->logid)) {
                     if ($logaction->action != 'completedChallenge') {
                         $actionitemcode = $this->buildActionItem($logaction);
                         if ($actionitemcode != '') {
                             $showCompletedChallengeEntry = false;
                             // suppress it if we can build a nicer display
                             $pointText = '<div class="storyBlockWrap"><p class="storyCaption"><span class="pointValue"> for ' . $data->pointsAwarded . '<span class="pts"> points </span></span></p></div>';
                             $code .= '<li id="actionFeedItem">' . $actionitemcode . $pointText . '</li>';
                         }
                     }
                 }
             }
             if ($showCompletedChallengeEntry) {
                 $action->itemid = $data->id;
                 $action->t = $data->dateSubmitted;
                 $code .= '<li id="actionFeedItem">' . $this->fetchChallengeCompletedFeedItem($action, $data->fbId, true, true) . '</li>';
             }
         }
         $code = '<div class="list_stories"><ul>' . $code . '</ul></div>';
     } else {
         $code .= $this->emptyLogMessage;
     }
     $pagingHTML = $this->feedPaging($currentPage, $rowTotal, $rowsPerPage, '', 'refreshFeed');
     // later put back page->rowsPerPage
     $code .= $pagingHTML;
     return $code;
 }
 function userWonPrize($userid, $prizeid)
 {
     require_once PATH_CORE . '/classes/log.class.php';
     $lt = new LogTable($this->db);
     $log = $lt->getRowObject();
     return $log->loadWhere("action='wonPrize' AND userid1={$userid} AND itemid={$prizeid}");
 }
예제 #9
0
 /**
  * Edit an alias.
  */
 public function editAction()
 {
     if (!$this->_alias) {
         $this->_alias = new Alias();
         if ($this->_domain) {
             $this->view->domainModel = $this->_domain;
         }
     } else {
         // if editing, then use that domain
         $this->view->domainModel = $this->_alias['Domain'];
     }
     $this->view->aliasModel = $this->_alias;
     $domainList = DomainTable::getDomains($this->getAdmin());
     $this->view->domainList = $domainList;
     $editForm = new ViMbAdmin_Form_Alias_Edit(null, $domainList);
     if ($this->getRequest()->isPost()) {
         if ($this->_alias['id']) {
             $editForm->removeElement('local_part');
             $editForm->removeElement('domain');
         }
         if ($editForm->isValid($_POST)) {
             $postValues = $editForm->getValues();
             if (isset($postValues['domain'])) {
                 $this->_domain = $this->loadDomain($postValues['domain']);
             }
             if (!$this->_domain || !$this->authorise(false, $this->_domain, false)) {
                 $this->addMessage(_("Invalid, unauthorised or non-existent domain."), ViMbAdmin_Message::ERROR);
                 $this->_redirect($this->getRequest()->getPathInfo());
             }
             if (!$this->_alias['id']) {
                 $alias = Doctrine::getTable('Alias')->findOneByAddress("{$postValues['local_part']}@{$this->_domain['domain']}");
                 if ($alias) {
                     if ($this->_options['mailboxAliases']) {
                         if ($alias->address == $alias->goto) {
                             $this->addMessage(_('A mailbox alias exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         } else {
                             $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                         }
                     } else {
                         $this->addMessage(_('Alias already exists for') . " {$postValues['local_part']}@{$this->_domain['domain']}", ViMbAdmin_Message::ERROR);
                     }
                     $this->_redirect($this->getRequest()->getPathInfo());
                 }
             }
             if (!$postValues['goto']) {
                 $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
             } else {
                 // is the alias valid (allowing for wildcard domains (i.e. with no local part)
                 if (!$this->_alias['id'] && $postValues['local_part'] != '' && !Zend_Validate::is("{$postValues['local_part']}@{$this->_domain['domain']}", 'EmailAddress', array(1, null))) {
                     $editForm->getElement('local_part')->addError(_('Invalid email address.'));
                 }
                 foreach ($postValues['goto'] as $key => $oneGoto) {
                     $oneGoto = trim($oneGoto);
                     if ($oneGoto == '') {
                         unset($postValues['goto'][$key]);
                     } else {
                         if (!Zend_Validate::is($oneGoto, 'EmailAddress', array(1, null))) {
                             $editForm->getElement('goto')->addError(_('Invalid email address(es).'));
                         }
                     }
                 }
                 if (!$postValues['goto']) {
                     $editForm->getElement('goto')->addError(_('You must have at least one goto address.'));
                 }
                 if (!$editForm->getElement('goto')->hasErrors() && ($editForm->getElement('local_part') === null || !$editForm->getElement('local_part')->hasErrors())) {
                     $this->_alias->fromArray($postValues);
                     if (!$this->_alias['id']) {
                         // do we have available mailboxes?
                         if (!$this->getAdmin()->isSuper() && $this->_domain['aliases'] != 0 && $this->_domain->countAliases() >= $this->_domain['aliases']) {
                             $this->_helper->viewRenderer->setNoRender(true);
                             $this->addMessage(_('You have used all of your allocated aliases.'), ViMbAdmin_Message::ERROR);
                             return print $this->view->render('close_colorbox_reload_parent.phtml');
                         }
                         $this->_alias['domain'] = $this->_domain['domain'];
                         $this->_alias['address'] = "{$postValues['local_part']}@{$this->_domain['domain']}";
                         LogTable::log('ALIAS_ADD', "Added {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     } else {
                         LogTable::log('ALIAS_EDIT', "Edited {$this->_alias['address']} -> {$this->_alias['goto']}", $this->getAdmin(), $this->_alias['domain']);
                     }
                     $this->_alias['goto'] = implode(',', array_unique($postValues['goto']));
                     $this->_alias->save();
                     $this->_helper->viewRenderer->setNoRender(true);
                     $this->addMessage(_('You have successfully added/edited the alias.'), ViMbAdmin_Message::SUCCESS);
                     return print $this->view->render('close_colorbox_reload_parent.phtml');
                 }
             }
         }
     } else {
         if ($this->_domain) {
             $editForm->getElement('domain')->setValue($this->_domain->id);
         }
         if ($this->_mailbox) {
             $this->view->defaultGoto = "{$this->_mailbox->local_part}@{$this->_mailbox->Domain->domain}";
         }
         if ($this->_alias['id']) {
             $editForm->setDefaults($this->_alias->toArray());
             $editForm->getElement('local_part')->setValue(str_replace("@{$this->_alias['domain']}", '', $this->_alias['address']))->setAttrib('disabled', 'disabled');
             $editForm->getElement('domain')->setAttrib('disabled', 'disabled');
         }
     }
     if ($this->_domain) {
         $editForm->getElement('domain')->setValue($this->_domain['id']);
     }
     $this->view->editForm = $editForm;
 }