/**
  * Add a note to an item
  *
  * @param unknown_type $toItem
  * @param unknown_type $note
  * @param unknown_type $title
  */
 public function addNoteTo($toItem, $note, $title = null, $username = null)
 {
     // get rid of multiple Re: bits in a title
     $title = preg_replace('|(Re: )+|i', 'Re: ', $title);
     $params = array('title' => $title, 'note' => $note, 'attachedtotype' => get_class($toItem), 'attachedtoid' => $toItem->id, 'userid' => $username == null ? za()->getUser()->getUsername() : $username);
     return $this->dbService->saveObject($params, 'Note');
 }
Exemple #2
0
 /**
  * Before allowing someone to do stuff, check to see
  * whether they have access to the file they've requested
  * 
  */
 public function preDispatch()
 {
     if (za()->getUser()->getRole() == User::ROLE_EXTERNAL) {
         // make sure the id is valid
         $id = $this->_getParam('id');
         $client = $this->clientService->getUserClient(za()->getUser());
         $project = $this->byId($this->_getParam('projectid'), 'Project');
         if ($client == null || $project == null) {
             $this->log->warn("User " . za()->getUser()->getUsername() . " tried viewing without valid client or project");
             $this->requireLogin();
             return;
         }
         if ($id) {
             // see whether the list of files for the current user's
             // company is valid
             /*$path = 'Clients/'.$client->title.'/Projects/'.$project->title;
             	            
             	            $okay = $this->fileService->isInDirectory($this->fileService->getFile($id), $path, true);
             
             	            if (!$okay) {
             	                $this->requireLogin();
             	            }*/
         }
     }
 }
Exemple #3
0
 public function indexAction()
 {
     $user = za()->getUser();
     // If it's an external user, redirect to the external module
     if ($user->getDefaultModule() != '') {
         // redirect appropriately
         $this->redirect('index', null, null, $user->getDefaultModule());
         return;
     }
     $this->view->items = $this->notificationService->getWatchedItems($user, array('Project', 'Client'));
     $cats = array();
     $start = date('Y-m') . '-01 00:00:00';
     $end = date('Y-m-t') . ' 23:59:59';
     $order = 'endtime desc';
     $startDay = date('Y-m-d') . ' 00:00:00';
     $endDay = date('Y-m-d') . ' 23:59:59';
     //    	$this->view->taskInfo = $this->projectService->getTimesheetReport($user, null, null, -1, $start, $end, $cats, $order);
     //    	$this->view->dayTasks = $this->projectService->getDetailedTimesheet($user, null, null, null, -1, $startDay, $endDay);
     $this->view->latest = $this->projectService->getProjects(array('ismilestone=' => 0), 'updated desc', 1, 10);
     $task = new Task();
     $this->view->categories = $task->constraints['category']->getValues();
     $this->view->startDate = $start;
     $this->view->endDate = $end;
     $this->view->favourites = $this->dbService->getObjects('PanelFavourite', array('creator=' => za()->getUser()->username));
     $this->renderView('index/index.php');
 }
Exemple #4
0
function reindex($items)
{
    $searchService = za()->getService('SearchService');
    foreach ($items as $item) {
        echo "Reindexing " . $item->title . "...   ";
        $searchService->index($item);
        echo "Done\r\n";
    }
}
Exemple #5
0
 public function listforuserAction()
 {
     $user = $this->userService->getUserByField('username', $this->_getParam('username'));
     if ($user == null) {
         $user = za()->getUser();
     }
     $this->view->user = $user;
     $this->view->reports = $this->expenseService->getExpenseReports(array('expensereport.username='******'expensereport.locked=' => '1', 'expensereport.paiddate<>' => 'null'));
     $this->renderView('expenses/list.php');
 }
 public function testDelete()
 {
     $searchService = za()->getService('SearchService');
     $example = new Task();
     $example->id = 1;
     $example->title = 'Task for testing';
     $example->description = "Task description for testing";
     $searchService->delete($example);
     $results = $searchService->search("testing");
     $this->assertEqual(count($results), 0);
 }
 /**
  * Create a user for the given contact. 
  */
 public function createuserAction()
 {
     $contact = $this->byId();
     try {
         $this->clientService->createUserForContact($contact);
     } catch (InvalidModelException $ime) {
         $this->flash($ime->getMessages());
         za()->log(print_r($ime->getMessages(), true), Zend_Log::ERR);
     }
     $this->redirect('contact', 'edit', array('id' => $contact->id));
 }
 /**
  * Load the contacts for a given client id
  */
 public function contactlistAction()
 {
     $client = $this->clientService->getUserClient(za()->getUser());
     if (!$client) {
         echo "Failed loading contacts";
         return;
     }
     $this->view->client = $client;
     $this->view->contacts = $this->clientService->getContacts($client);
     $this->renderRawView('contact/ajax-list.php');
 }
Exemple #9
0
 /**
  * View a single client
  *
  */
 public function viewAction()
 {
     $this->view->client = $this->byId();
     $this->view->title = $this->view->client->title;
     $this->view->existingWatch = $this->notificationService->getWatch(za()->getUser(), $this->view->client);
     if ($this->_getParam('_ajax')) {
         $this->renderRawView('client/ajaxView.php');
     } else {
         $this->renderView('client/view.php');
     }
 }
Exemple #10
0
 public function execute()
 {
     $server = za()->getConfig('support_mail_server');
     $user = za()->getConfig('support_email_user');
     $pass = za()->getConfig('support_email_pass');
     if (!$server || !$user || !$pass) {
         // exit!
         throw new Exception("Configuration incorrect for checking issue emails");
     }
     $emails = $this->emailService->readEmailFrom($server, $user, $pass, true);
     $this->issueService->processIncomingEmails($emails);
 }
Exemple #11
0
 /**
  * Called before Zend_Controller_Front enters its dispatch loop.
  * During the dispatch loop.
  *
  * This callback allows for proxy or filter behavior.  The
  * $action must be returned for the Zend_Controller_Dispatcher_Token to enter the
  * dispatch loop.  To abort before the dispatch loop is
  * entered, return FALSE.
  *
  * @param  Zend_Controller_Dispatcher_Token|boolean $action
  * @return Zend_Controller_Dispatcher_Token|boolean
  */
 public function dispatchLoopStartup($action)
 {
     // Checks PHP_AUTH_USER and PHP_AUTH_PW and uses those values
     // to authenticate a user
     if (!za()->getUser()->getId() > 0 && isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
         // Get the auth service and authenticate the user
         $auth = za()->getService('AuthService');
         /* @var $auth AuthService */
         $user = $auth->authenticate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
     }
     return $action;
 }
Exemple #12
0
 /**
  * Before rendering, we'll add some extra stuff into the view!
  *
  */
 protected function renderView($script)
 {
     if (za()->getUser()->hasRole(User::ROLE_USER)) {
         $this->view->actionList = new CompositeView('layouts/actions-list.php');
         // Let's get a bunch of the current user's oldest incomplete
         // tasks to put in the list.
         $projectService = za()->getService('ProjectService');
         /* @var $projectService ProjectService */
         $this->view->actionList->tasks = $projectService->getUserTasks(za()->getUser(), array('complete=' => 0));
     }
     parent::renderView($script);
 }
 function testListDirectory()
 {
     $fileService = za()->getService('FileService');
     /* @var $fileService AlfrescoFileService */
     try {
         $file = $fileService->createFile('sample_file.txt', '/My');
         $fileService->setFile($file, __FILE__);
     } catch (FileExistsException $fee) {
         // don't do anything, we don't really care
     }
     $list = $fileService->listDirectory('/My');
     $this->assertEqual(3, count($list));
 }
Exemple #14
0
 public function preDispatch()
 {
     $userClient = $this->clientService->getUserClient(za()->getUser());
     if ($userClient != null) {
         $id = $this->_getParam('id');
         // get the user's client
         if ($id != $userClient->id) {
             $this->_setParam('id', $userClient->id);
         }
     } else {
         $this->requireLogin();
     }
 }
Exemple #15
0
 /**
  * Edit a user object.
  *
  */
 public function editAction()
 {
     $id = (int) $this->_getParam('id');
     $userToEdit = za()->getUser();
     // if the user's an admin, give them the list of contacts
     // to bind for this user
     if (za()->getUser()->isPower()) {
         // get all the contacts
         $this->view->contacts = $this->clientService->getContacts();
     }
     $this->view->model = $userToEdit;
     $this->renderView('user/edit.php');
 }
Exemple #16
0
 public function execute()
 {
     $issues = $this->issueService->getIssues(array('status=' => 'Open'));
     // Get the project for each issue
     $group = $this->groupService->getGroupByField('title', za()->getConfig('issue_group'));
     if ($group) {
         $users = $this->groupService->getUsersInGroup($group);
         $msg = new TemplatedMessage('open-issues.php', array('issues' => $issues));
         $this->notificationService->notifyUser('Open Requests', $users, $msg);
     } else {
         za()->log()->warn("Could not find group for sending issues to");
     }
 }
Exemple #17
0
 /**
  * Track an action
  *
  * @param unknown_type $actionname
  * @param unknown_type $actionid
  * @param unknown_type $user
  * @param unknown_type $url
  */
 public function track($actionname, $actionid, $user = null, $url = null, $data = null)
 {
     $params = array();
     if ($user == null) {
         $params['user'] = za()->getUser()->getUsername();
     }
     if ($url == null) {
         $params['url'] = current_url();
     }
     $params['actionname'] = $actionname;
     $params['actionid'] = $actionid;
     $params['entrydata'] = $data;
     $this->trackAction($params);
 }
 function testGetExpenses()
 {
     $dbService = za()->getService('DbService');
     /* @var $dbService DbService */
     $dbService->delete('expense');
     $dbService->delete('client');
     $clientService = za()->getService('ClientService');
     /* @var $clientService ClientService */
     $expenseService = za()->getService('ExpenseService');
     /* @var $clientService ExpenseService */
     $params['title'] = 'Client';
     $client = $clientService->saveClient($params);
     $expense1 = array('description');
 }
Exemple #19
0
 public function testCreateClient()
 {
     $dbService = za()->getService('DbService');
     /* @var $dbService DbService */
     $dbService->delete('client');
     $clientService = za()->getService('ClientService');
     /* @var $clientService ClientService */
     $params['title'] = 'Client';
     $client = $clientService->saveClient($params);
     $project = $clientService->getClientSupportProject($client);
     $this->assertEqual('Client Support', $project->title);
     // Try again to force loading.
     $project = $clientService->getClientSupportProject($client);
     $this->assertEqual('Client Support', $project->title);
 }
 public function testImportGantt()
 {
     $projectService = za()->getService('ProjectService');
     /* @var $projectService ProjectService */
     $projectService->dbService->delete('project');
     $projectService->dbService->delete('task');
     $projectService->dbService->delete('usertaskassignment');
     $params['title'] = "My Project";
     $project = $projectService->saveProject($params);
     $projectService->importTasks($project, dirname(__FILE__) . '/POC.csv', 'ms');
     $exporter = $projectService->exportTasks($project, 'gp');
     print_r($exporter->getHeaderRow());
     while ($row = $exporter->getNextDataRow()) {
         print_r($row);
     }
 }
Exemple #21
0
    public function RequestValidator($tokenOnly = false)
    {
        $token = za()->getSession()->novemberValidationToken;
        if ($token == null) {
            $token = md5(mt_rand());
            za()->getSession()->novemberValidationToken = $token;
        }
        if ($tokenOnly) {
            return $token;
        }
        ?>
		<input type="hidden" name="__validation_token" value="<?php 
        echo $token;
        ?>
" />
		<?php 
    }
Exemple #22
0
function query_log()
{
    $app = za();
    if ($app->getConfig('log_queries')) {
        $profiler = $app->getService('DbService')->getProfiler();
        $total = $profiler->getTotalNumQueries();
        //za()->log("DB Query Log");
        za()->log("\n\n\n***************************\n***************************\n\n");
        $elapsed = 0;
        for ($i = 0; $i < $total; $i++) {
            $profile = $profiler->getQueryProfile($i);
            $elapsed += $profile->getElapsedSecs();
            za()->log("\n" . $profile->getElapsedSecs() . "s\n" . $profile->getQuery());
        }
        za()->log("Total of {$total} queries, {$elapsed} seconds in total");
    }
}
Exemple #23
0
 /**
  * Get the amount of elapsed time for a given number of seconds.
  *
  * @return  NovemberUser
  */
 public function HoursAsDays($hours, $dayDivision = 0, $dayLength = 0, $divisionTolerance = 0)
 {
     if ($hours > 0) {
         $divisionTolerance = $divisionTolerance ? $divisionTolerance : za()->getConfig('division_tolerance', 20);
         $dayLength = $dayLength ? $dayLength : za()->getConfig('day_length', 7.5);
         $dayDivision = $dayDivision ? $dayDivision : $dayLength / 4;
         $dayPercentage = $dayDivision / $dayLength;
         $hoursAsDays = floor($hours / $dayDivision) * $dayPercentage + $dayPercentage;
         // if the time was only a little above a day division, lets be nice to our
         // clients and drop off that quarter day charge
         $overDraft = fmod($hours, $dayDivision);
         if ($overDraft < $dayDivision * ($divisionTolerance / 100)) {
             $hoursAsDays -= $dayPercentage;
         }
         return $hoursAsDays;
     }
 }
Exemple #24
0
 /**
  * Get the posts in this feed. 
  *
  */
 public function getPosts()
 {
     if ($this->items == null) {
         $this->items = array();
         $doc = null;
         try {
             $doc = new SimpleXmlElement($this->content);
             $items = $doc->item;
             foreach ($items as $item) {
                 $dc = $item->children('http://purl.org/dc/elements/1.1/');
                 $this->items[] = array('title' => $item->title, 'link' => $item->link, 'description' => $dc->subject, 'date' => $dc->date, 'creator' => $dc->creator);
             }
         } catch (Exception $e) {
             za()->log("Failed parsing feed", Zend_Log::ERR);
         }
     }
     return $this->items;
 }
 /**
  * Is the model valid? 
  * @return boolean
  */
 public function isValid($model)
 {
     // first, search for another
     $prop = $this->propertyName;
     $value = $model->{$prop};
     if (empty($value)) {
         return true;
     }
     // okay, search for it using the DB service
     $dbService = za()->getService('DbService');
     /* @var $dbService DbService */
     $existing = $dbService->getByField(array($prop => $value), get_class($model));
     if ($existing && $existing->id != $model->id) {
         $this->messages[] = get_class($model) . " with {$prop} value '{$value}' already exists";
         return false;
     }
     return true;
 }
 public function testAuthorization()
 {
     $app = za();
     za()->setUser(new GuestUser());
     $pluginConf = $app->getConfig('plugins');
     $conf = array('default' => array('user' => array('edit' => 'User,Admin', 'list' => 'Admin')), 'login_controller' => 'testcontroller', 'login_action' => 'testaction');
     $plugin = new AuthorizationPlugin($conf);
     $action = new Zend_Controller_Request_Http();
     $action->setControllerName("user");
     $action->setActionName('edit');
     $action->setModuleName('default');
     $plugin->preDispatch($action);
     // Make sure it's redirected to the user / login controller
     $this->assertEqual($action->getControllerName(), 'testcontroller');
     $this->assertEqual($action->getActionName(), 'testaction');
     // Now test that a user with role User is fine
     $user = new User();
     za()->setUser($user);
     $user->role = 'User';
     $action->setControllerName("user");
     $action->setActionName('edit');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'edit');
     // Make sure they can't LIST
     $action->setControllerName('user');
     $action->setActionName('list');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'testcontroller');
     $this->assertEqual($action->getActionName(), 'testaction');
     // Now make them an admin, make sure they can do both the above
     $user->role = 'Admin';
     $action->setControllerName("user");
     $action->setActionName('edit');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'edit');
     // Make sure they can't LIST
     $action->setControllerName('user');
     $action->setActionName('list');
     $plugin->preDispatch($action);
     $this->assertEqual($action->getControllerName(), 'user');
     $this->assertEqual($action->getActionName(), 'list');
 }
Exemple #27
0
    /**
     * Allows the dispatching and processing of a separate 
     * controller request from inside an existing view. 
     * 
     * Should be used for read only stuff (please!)
     *
     * @param string $controller
     * @param string $action
     * @param array $params A list of parameters to bind into the new request
     * @param string $module
     * @param array $requestParams A list of parameters to pull from the current request
     */
    public function AjaxDispatch($controller, $action, $params = array(), $module = null, $requestParams = array())
    {
        $key = $controller . '-' . $action . '-' . $module;
        if (isset(self::$__DISPATCHED[$key])) {
            za()->log("Recursive dispatch detected {$key} ", Zend_Log::ERR);
            return;
        }
        self::$__DISPATCHED[$key] = true;
        $ctrl = Zend_Controller_Front::getInstance();
        $oldRequest = $ctrl->getRequest();
        if (count($requestParams)) {
            foreach ($requestParams as $rp) {
                // get from the current request and stick into the new
                $value = $oldRequest->getParam($rp, '');
                $params[$rp] = $value;
            }
        }
        $id = $key;
        $params['__ignorelayout'] = 1;
        $url = build_url($controller, $action, $params, false, $module);
        ?>
        <div id="<?php 
        echo $id;
        ?>
" class="load-target" name="<?php 
        echo $url;
        ?>
"></div>
        <script type="text/javascript">
        $().ready(function() {
        	var dispatchElem = $('#<?php 
        echo $id;
        ?>
');
        	dispatchElem.load('<?php 
        echo $url;
        ?>
');
        	});
        </script>
        <?php 
        return;
    }
 public function testAddNote()
 {
     $dbService = za()->getService('DbService');
     /* @var $dbService DbService */
     $dbService->delete('client');
     $dbService->delete('note');
     $clientService = za()->getService('ClientService');
     /* @var $clientService ClientService */
     $notificationService = za()->getService('NotificationService');
     /* @var $notificationService NotificationService */
     $params['title'] = 'Client';
     $client = $clientService->saveClient($params);
     // Add a note to that client
     $notificationService->addNoteTo($client, "This is a note", "Note Title");
     $notes = $notificationService->getNotesFor($client);
     $this->assertEqual(1, count($notes));
     $this->assertEqual('This is a note', $notes[0]->note);
     $this->assertEqual('Note Title', $notes[0]->title);
 }
Exemple #29
0
 public function configure($config)
 {
     if (isset($config['index'])) {
         try {
             Zend_Search_Lucene_Analysis_Analyzer::setDefault(new AlphaNumAnalyzer());
             $this->indexPath = BASE_DIR . $config['index'];
             if (!is_dir($this->indexPath)) {
                 $this->index = Zend_Search_Lucene::create($this->indexPath);
             } else {
                 $this->index = Zend_Search_Lucene::open($this->indexPath);
             }
         } catch (Zend_Search_Lucene_Exception $zsle) {
             // probably a readonly index?
             // ignore so we can continue.
             za()->log("Failed opening index: " . $zsle->getMessage(), Zend_Log::ERR);
             za()->log($zsle->getTraceAsString(), Zend_Log::ERR);
         }
     }
 }
Exemple #30
0
 function testListDirectory()
 {
     $dbService = za()->getService('DbService');
     /* @var $dbService DbService */
     $dbService->delete('file');
     $fileService = za()->getService('FileService');
     /* @var $fileService FileService */
     $file = $fileService->createFile('Company Home/client/new_file.txt');
     $this->assertEqual($file->filename, 'new_file.txt');
     $this->assertEqual($file->path, '/Company Home/client');
     $this->assertTrue(is_file(APP_DIR . '/testing/data/files/Company Home/client/new_file.txt'));
     $anotherFile = $fileService->createFile('Company Home/client/another_file.txt');
     $this->assertEqual($anotherFile->filename, 'another_file.txt');
     $this->assertEqual($anotherFile->path, '/Company Home/client');
     $this->assertTrue(is_file(APP_DIR . '/testing/data/files/Company Home/client/another_file.txt'));
     $fileService->createDirectory('/Company Home/client/another_Folder');
     $listing = $fileService->listDirectory('/Company Home/client');
     // okay, get the listing
     $this->assertEqual(3, count($listing));
 }