/**
  * Group tasks by kanban type and get stats
  * @param Project $project
  * @return array
  */
 protected static function groupTasksByKanbanTypeAndGetStats(Project $project)
 {
     $tasks = $project->tasks;
     $kanbanItemsArray = array();
     $totalTasksToDoCount = 0;
     $completedTasksCount = 0;
     foreach ($tasks as $task) {
         if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($task, Permission::READ)) {
             $totalTasksToDoCount++;
             if ($task->status == Task::STATUS_COMPLETED) {
                 $completedTasksCount++;
             }
             $kanbanItem = KanbanItem::getByTask($task->id);
             if ($kanbanItem == null) {
                 //Create KanbanItem here
                 $kanbanItem = TasksUtil::createKanbanItemFromTask($task);
             }
             $kanbanItemsArray[$kanbanItem->type][] = $kanbanItem->id;
         }
     }
     $stats = array();
     $kanbanTypeDropDownData = KanbanItem::getTypeDropDownArray();
     foreach ($kanbanTypeDropDownData as $type => $label) {
         if (isset($kanbanItemsArray[$type])) {
             $stats[$type] = count($kanbanItemsArray[$type]);
         } else {
             $stats[$type] = 0;
         }
     }
     $stats['completionPercent'] = static::resolveCompletionPercentage($completedTasksCount, $totalTasksToDoCount);
     return $stats;
 }
 public function renderContent()
 {
     $accessContent = $this->resolveContentIfCurrentUserCanAccessChartByModule('OpportunitiesModule', 'OpportunitiesModulePluralLabel');
     if ($accessContent != null) {
         return $accessContent;
     }
     $chartDataProviderType = $this->getChartDataProviderType();
     $chartDataProvider = ChartDataProviderFactory::createByType($chartDataProviderType);
     ControllerSecurityUtil::resolveCanCurrentUserAccessModule($chartDataProvider->getModel()->getModuleClassName(), true);
     $chartData = $chartDataProvider->getChartData();
     Yii::import('ext.amcharts.AmChartMaker');
     $amChart = new AmChartMaker();
     $amChart->data = $chartData;
     $amChart->id = $this->uniqueLayoutId;
     $amChart->type = $this->resolveViewAndMetadataValueByName('type');
     $amChart->addSerialGraph('value', 'column');
     $amChart->xAxisName = $chartDataProvider->getXAxisName();
     $amChart->yAxisName = $chartDataProvider->getYAxisName();
     $amChart->yAxisUnitContent = Yii::app()->locale->getCurrencySymbol(Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay());
     $javascript = $amChart->javascriptChart();
     Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->uniqueLayoutId, $javascript);
     $cClipWidget = new CClipWidget();
     $cClipWidget->beginClip("Chart");
     $cClipWidget->widget('application.core.widgets.AmChart', array('id' => $this->uniqueLayoutId));
     $cClipWidget->endClip();
     return $cClipWidget->getController()->clips['Chart'];
 }
 /**
  * Resolve html for a builder template provided the model itself.
  * @param EmailTemplate $emailTemplate
  * @param bool $renderForCanvas
  * @param OwnedSecurableItem $attachedMergeTagModel
  * @return bool|null|string
  */
 public static function resolveHtmlByEmailTemplateModel(EmailTemplate $emailTemplate, $renderForCanvas = false, OwnedSecurableItem $attachedMergeTagModel = null)
 {
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($emailTemplate);
     $serializedData = $emailTemplate->serializedData;
     $resolvedHtml = static::resolveHtmlBySerializedData($serializedData, $renderForCanvas, $attachedMergeTagModel, $emailTemplate->type, $emailTemplate->language);
     return $resolvedHtml;
 }
 /**
  * Resolve html for a builder template provided the model itself.
  * @param EmailTemplate $emailTemplate
  * @param bool $renderForCanvas
  * @return bool|null|string
  */
 public static function resolveHtmlByEmailTemplateModel(EmailTemplate $emailTemplate, $renderForCanvas = false)
 {
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($emailTemplate);
     $serializedData = $emailTemplate->serializedData;
     $resolvedHtml = static::resolveHtmlBySerializedData($serializedData, $renderForCanvas);
     return $resolvedHtml;
 }
 /**
  * Action for saving an existing note inline edit form.
  * @param string or array $redirectUrl
  */
 public function actionInlineEditSave($id, $redirectUrl = null)
 {
     $note = Note::getById((int) $id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($note);
     if (isset($_POST['ajax']) && $_POST['ajax'] === 'inline-edit-form') {
         $this->actionInlineEditValidate($note, 'Note');
     }
     $this->attemptToSaveModelFromPost($note, $redirectUrl);
 }
 public function actionDetails($id)
 {
     $deptReference = static::getModelAndCatchNotFoundAndDisplayError('DepartmentReference', intval($id));
     $breadCrumbView = StickySearchUtil::resolveBreadCrumbViewForDetailsControllerAction($this, 'DepartmentReferencesSearchView', $deptReference);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($deptReference);
     AuditEvent::logAuditEvent('ZurmoModule', ZurmoModule::AUDIT_EVENT_ITEM_VIEWED, array(strval($deptReference), 'DepartmentReferencesModule'), $deptReference);
     $titleBarAndEditView = $this->makeEditAndDetailsView($deptReference, 'Details');
     $view = new DepartmentReferencesPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $titleBarAndEditView));
     echo $view->render();
 }
Example #7
0
 public function actionCloseTask($id)
 {
     $task = Task::getById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($task);
     $task->completedDateTime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
     $task->completed = true;
     $saved = $task->save();
     if (!$saved) {
         throw new NotSupportedException();
     }
 }
 /**
  * Render totals in a product portlet view
  */
 protected function renderTotalBarDetails()
 {
     $persistantProductConfigItemValue = ProductsPortletPersistentConfigUtil::getForCurrentUserByPortletIdAndKey($this->params['portletId'], 'filteredByStage');
     $relationModelClassName = get_class($this->params["relationModel"]);
     $relationModelId = $this->params["relationModel"]->id;
     $relationModel = $relationModelClassName::getById($relationModelId);
     $models = $relationModel->products;
     $oneTimeTotal = 0;
     $monthlyTotal = 0;
     $annualTotal = 0;
     foreach ($models as $model) {
         if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($model, Permission::READ)) {
             if ($persistantProductConfigItemValue === null) {
                 $persistantProductConfigItemValue = ProductsConfigurationForm::FILTERED_BY_ALL_STAGES;
             }
             if ($persistantProductConfigItemValue != ProductsConfigurationForm::FILTERED_BY_ALL_STAGES) {
                 if ($model->stage->value != $persistantProductConfigItemValue) {
                     continue;
                 }
             }
             if ($model->priceFrequency == ProductTemplate::PRICE_FREQUENCY_ONE_TIME) {
                 $oneTimeTotal += $this->getAdjustedTotalByCurrency($model);
             }
             if ($model->priceFrequency == ProductTemplate::PRICE_FREQUENCY_MONTHLY) {
                 $monthlyTotal += $this->getAdjustedTotalByCurrency($model);
             }
             if ($model->priceFrequency == ProductTemplate::PRICE_FREQUENCY_ANNUALLY) {
                 $annualTotal += $this->getAdjustedTotalByCurrency($model);
             }
         }
     }
     $content = Zurmo::t("Core", "Total: ");
     $contentArray = array();
     if ($oneTimeTotal > 0) {
         $contentArray[] = Yii::app()->numberFormatter->formatCurrency($oneTimeTotal, Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay()) . Zurmo::t("Core", " One Time");
     }
     if ($monthlyTotal > 0) {
         $contentArray[] = Yii::app()->numberFormatter->formatCurrency($monthlyTotal, Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay()) . Zurmo::t("Core", " Monthly");
     }
     if ($annualTotal > 0) {
         $contentArray[] = Yii::app()->numberFormatter->formatCurrency($annualTotal, Yii::app()->currencyHelper->getCodeForCurrentUserForDisplay()) . Zurmo::t("Core", " Annually");
     }
     if (empty($contentArray)) {
         $content = '';
     } else {
         $content .= implode(', ', $contentArray);
     }
     echo $content;
 }
 public function actionDetails($id, $runReport = false)
 {
     $savedReport = SavedReport::getById((int) $id);
     ControllerSecurityUtil::resolveCanCurrentUserAccessModule($savedReport->moduleClassName);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($savedReport, true);
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $report, 'redirectUrl' => Yii::app()->request->getRequestUri(), 'dataProvider' => $this->getDataProvider($report, $report->getId(), (bool) $runReport));
     $portletView = $portlet->getView();
     if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel)) {
         $messageView = new AccessFailureView();
         $view = new AccessFailurePageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $view = new AjaxPageView($portletView);
     echo $view->render();
 }
 public function actionSendTestEmail($id, $contactId = null, $emailAddress = null, $useHtmlContent = 1)
 {
     $emailTemplate = EmailTemplate::getById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($emailTemplate);
     $htmlContent = $emailTemplate->htmlContent;
     if (!$useHtmlContent) {
         $htmlContent = EmailTemplateSerializedDataToHtmlUtil::resolveHtmlByEmailTemplateModel($emailTemplate, false);
     }
     $contact = null;
     if (isset($contactId)) {
         $contact = Contact::getById(intval($contactId));
     }
     static::resolveEmailMessage($emailTemplate, $contact, $htmlContent, $emailAddress);
 }
 /**
  * @param $id
  * @param null $redirectUrl
  */
 public function actionDelete($id, $redirectUrl = null)
 {
     if ($redirectUrl == null) {
         $redirectUrl = array('/home/default');
     }
     $modelClassName = $this->getModule()->getPrimaryModelName();
     $activity = $modelClassName::getById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($activity);
     $activity->delete();
     $this->redirect($redirectUrl);
 }
 public function actionGetAccountAddressesToCopy($id)
 {
     $account = static::getModelAndCatchNotFoundAndDisplayError('Account', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($account);
     $addressData = array();
     foreach ($account->billingAddress->getAttributeNames() as $attribute) {
         $addressData['billingAddress_' . $attribute] = $account->billingAddress->{$attribute};
     }
     foreach ($account->shippingAddress->getAttributeNames() as $attribute) {
         $addressData['shippingAddress_' . $attribute] = $account->shippingAddress->{$attribute};
     }
     echo CJSON::encode($addressData);
 }
 /**
  * @depends testResolveAccessCanCurrentUserWriteModel
  */
 public function testResolveAccessCanCurrentUserDeleteModel()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $accounts = Account::getByName('Supermart');
     $this->assertEquals(1, count($accounts));
     $betty = User::getByUsername('betty');
     Yii::app()->user->userModel = $betty;
     $this->startOutputBuffer();
     try {
         ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($accounts[0], true);
         $this->endPrintOutputBufferAndFail();
     } catch (ExitException $e) {
         $content = $this->endAndGetOutputBuffer();
         $this->assertEquals('failure', $content);
     }
     $this->startOutputBuffer();
     try {
         ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($accounts[0], false);
         $this->endPrintOutputBufferAndFail();
     } catch (ExitException $e) {
         $compareString = 'You have tried to access a page you do not have access to';
         $this->assertContains($compareString, $this->endAndGetOutputBuffer());
     }
     $accounts = Account::getByName('BettyInc');
     $this->assertEquals(1, count($accounts));
     $account = $accounts[0];
     $this->startOutputBuffer();
     try {
         ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($account, true);
         ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($account, false);
         $content = $this->endAndGetOutputBuffer();
         $this->assertEquals(null, $content);
     } catch (ExitException $e) {
         $this->endPrintOutputBufferAndFail();
     }
 }
 protected function resolveAfterSaveHasPermissionsProblem(SavedReport $savedReport, $modelToStringValue)
 {
     assert('is_string($modelToStringValue)');
     if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($savedReport, Permission::READ)) {
         return false;
     } else {
         $notificationContent = Zurmo::t('ZurmoModule', 'You no longer have permissions to access {modelName}.', array('{modelName}' => $modelToStringValue));
         Yii::app()->user->setFlash('notification', $notificationContent);
         return true;
     }
 }
Example #15
0
 public function actionDelete($id)
 {
     $animal = Animal::GetById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($animal);
     $animal->delete();
     $this->redirect(array($this->getId() . '/index'));
 }
 public function actionUnlink($id)
 {
     $relationModelClassName = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelClassName');
     $relationModelId = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelId');
     $relationModelRelationName = ArrayUtil::getArrayValue(GetUtil::getData(), 'relationModelRelationName');
     if ($relationModelClassName == null || $relationModelId == null || $relationModelRelationName == null) {
         throw new NotSupportedException();
     }
     $relationModel = $relationModelClassName::GetById(intval($relationModelId));
     if ($relationModel->getRelationType($relationModelRelationName) != RedBeanModel::HAS_MANY && $relationModel->getRelationType($relationModelRelationName) != RedBeanModel::MANY_MANY) {
         throw new NotSupportedException();
     }
     $modelClassName = $relationModel->getRelationModelClassName($relationModelRelationName);
     $model = $modelClassName::getById((int) $id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($model);
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($relationModel);
     $relationModel->{$relationModelRelationName}->remove($model);
     $saved = $relationModel->save();
     if (!$saved) {
         throw new FailedToSaveModelException();
     }
 }
 public function actionDelete($id)
 {
     $contact = Contact::GetById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($contact);
     if (!LeadsUtil::isStateALead($contact->state)) {
         $urlParams = array('/contacts/' . $this->getId() . '/delete', 'id' => $contact->id);
         $this->redirect($urlParams);
     } else {
         $contact->delete();
         $this->redirect(array($this->getId() . '/index'));
     }
 }
 /**
  * Copies the product
  * @param int $id
  */
 public function actionCopy($id)
 {
     $copyToProduct = new Product();
     $postVariableName = get_class($copyToProduct);
     if (!isset($_POST[$postVariableName])) {
         $product = Product::getById((int) $id);
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($product);
         ProductZurmoCopyModelUtil::copy($product, $copyToProduct);
     }
     $this->processEdit($copyToProduct);
 }
Example #19
0
 public function actionDelete($id)
 {
     $emailTemplate = static::getModelAndCatchNotFoundAndDisplayError('EmailTemplate', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($emailTemplate);
     $type = $emailTemplate->type;
     $emailTemplate->delete();
     if ($type == EmailTemplate::TYPE_WORKFLOW) {
         $this->redirect(array($this->getId() . '/listForWorkflow'));
     } elseif ($emailTemplate->type == EmailTemplate::TYPE_CONTACT) {
         $this->redirect(array($this->getId() . '/listForMarketing'));
     } else {
         throw new NotSupportedException();
     }
 }
 public function actionUsersInGroupModalList($id)
 {
     $model = Group::getById((int) $id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($model);
     $searchAttributeData = UsersByModelModalListControllerUtil::makeModalSearchAttributeDataByModel($model, 'groups');
     $dataProvider = UsersByModelModalListControllerUtil::makeDataProviderBySearchAttributeData($searchAttributeData);
     Yii::app()->getClientScript()->setToAjaxMode();
     echo UsersByModelModalListControllerUtil::renderList($this, $dataProvider, 'usersInGroupModalList');
 }
 /**
  * If a current user cannot write the module, then render a AccessFailurePageView
  * and end the application.
  * @param $model - RedBeanModel
  * @return null;
  */
 public static function resolveAccessCanCurrentUserWriteModule($moduleClassName, $fromAjax = false)
 {
     assert('is_string($moduleClassName)');
     $item = NamedSecurableItem::getByName($moduleClassName);
     if (ControllerSecurityUtil::doesCurrentUserHavePermissionOnSecurableItem($item, Permission::WRITE)) {
         return;
     }
     static::processAccessFailure($fromAjax);
     Yii::app()->end(0, false);
 }
 public function actionDrillDownDetails($campaignItemId)
 {
     $id = (int) $campaignItemId;
     $campaignItem = CampaignItem::getById($id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($campaignItem->campaign);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($campaignItem->contact);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($campaignItem->emailMessage);
     echo CampaignItemSummaryListViewColumnAdapter::resolveDrillDownMetricsSummaryContent($campaignItem);
 }
 protected function resolveSavedWorkflowAndWorkflowByPostData(array $postData, &$savedWorkflow, &$workflow, $type, $id = null, $isBeingCopied = false)
 {
     if ($id == null) {
         $this->resolveCanCurrentUserAccessWorkflows();
         $savedWorkflow = new SavedWorkflow();
         $workflow = new Workflow();
         $workflow->setType($type);
     } elseif ($isBeingCopied) {
         $savedWorkflow = new SavedWorkflow();
         $oldWorkflow = SavedWorkflow::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($oldWorkflow);
         ZurmoCopyModelUtil::copy($oldWorkflow, $savedWorkflow);
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     } else {
         $savedWorkflow = SavedWorkflow::getById(intval($id));
         ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($savedWorkflow);
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
     }
     DataToWorkflowUtil::resolveWorkflowByWizardPostData($workflow, $postData, WorkflowToWizardFormAdapter::getFormClassNameByType($type));
 }
Example #24
0
 public function actionCopy($id)
 {
     $copyToOpportunity = new Opportunity();
     $postVariableName = get_class($copyToOpportunity);
     if (!isset($_POST[$postVariableName])) {
         $opportunity = Opportunity::getById((int) $id);
         ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($opportunity);
         ZurmoCopyModelUtil::copy($opportunity, $copyToOpportunity);
     }
     $this->processEdit($copyToOpportunity);
 }
 protected function getPortletViewForDetails($id)
 {
     $id = intval($id);
     $modelName = $this->getModule()->getPrimaryModelName();
     $model = $modelName::getById($id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($model, true);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     if (null != ($redirectUrl = ArrayUtil::getArrayValue($_GET, 'redirectUrl'))) {
         $redirectUrl = $redirectUrl;
     } else {
         $redirectUrl = Yii::app()->request->getRequestUri();
     }
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $model, 'redirectUrl' => $redirectUrl);
     $portletView = $portlet->getView();
     return $portletView;
 }
 public function actionGetDepartmentReferenceLaborCostAndBurdonCostToCopy($id)
 {
     $departmentReference = static::getModelAndCatchNotFoundAndDisplayError('DepartmentReference', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($departmentReference);
     $data = array();
     if ($departmentReference->laborCost != null) {
         $data['laborCost'] = $departmentReference->laborCost;
     }
     if ($departmentReference->burdonCost != null) {
         $data['burdonCost'] = $departmentReference->burdonCost;
     }
     echo CJSON::encode($data);
 }
Example #27
0
 public function actionDelete($id)
 {
     $contactWebForm = ContactWebForm::getById(intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserDeleteModel($contactWebForm);
     $contactWebForm->delete();
     $this->redirect(array($this->getId() . '/index'));
 }
 /**
  * Used by my portlets to process or render actions on the portlet's view. An example is changing the
  * month of the calendar, requires additional calendar events to be loaded.
  * @param integer $id
  */
 public function actionViewAction($id, $action)
 {
     $id = intval($id);
     $modelName = $this->getModule()->getPrimaryModelName();
     $model = $modelName::getById($id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($model, true);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $model, 'redirectUrl' => Yii::app()->request->getRequestUri());
     $portletView = $portlet->getView();
     if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel)) {
         Yii::app()->end(0, false);
     }
     $portletView->{$action}();
 }
 protected function addNewSubscribers($marketingListId, $contactIds, $scenario = null)
 {
     $subscriberInformation = array('subscribedCount' => 0, 'skippedCount' => 0);
     $marketingList = MarketingList::getById((int) $marketingListId);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($marketingList);
     foreach ($contactIds as $contactId) {
         if ($marketingList->addNewMember($contactId, false, null, $scenario)) {
             $subscriberInformation['subscribedCount']++;
         } else {
             $subscriberInformation['skippedCount']++;
         }
     }
     return $subscriberInformation;
 }
 public function actionGetInfoToCopyToCampaign($id)
 {
     $marketingList = static::getModelAndCatchNotFoundAndDisplayError('MarketingList', intval($id));
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($marketingList);
     $data = array();
     $data['fromName'] = $marketingList->fromName;
     $data['fromAddress'] = $marketingList->fromAddress;
     echo CJSON::encode($data);
 }