예제 #1
0
파일: Module.php 프로젝트: ajaboa/crmpuan
 /**
  * Install's a module with all it's dependencies
  * 
  * @param string $moduleId
  * @return \GO\Base\Model\Module
  * @throws \GO\Base\Exception\Save
  */
 public static function install($moduleId, $ignoreDependentModule = false)
 {
     GO::debug("install({$moduleId},{$ignoreDependentModule})");
     if (!($module = Module::model()->findByPk($moduleId, false, true))) {
         $module = new Module();
         $module->id = $moduleId;
         $dependencies = $module->moduleManager->getDependencies();
         foreach ($dependencies as $dependency) {
             if ($ignoreDependentModule !== $dependency) {
                 self::install($dependency, $moduleId);
             }
         }
         if (!$module->save()) {
             throw new \GO\Base\Exception\Save();
         }
     } else {
         if (!$module->enabled) {
             $module->enabled = true;
             $dependencies = $module->moduleManager->getDependencies();
             GO::debug($dependencies);
             foreach ($dependencies as $dependency) {
                 if ($ignoreDependentModule !== $dependency) {
                     self::install($dependency, $moduleId);
                 }
             }
             $module->save();
         }
     }
     return $module;
 }
예제 #2
0
 public static function loadSettings(&$settingsController, &$params, &$response, $user)
 {
     $startModule = \GO\Base\Model\Module::model()->findByPk($user->start_module);
     $response['data']['start_module_name'] = $startModule ? $startModule->moduleManager->name() : '';
     $company = \GO\Addressbook\Model\Company::model()->findByPk($response['data']['company_id'], false, true);
     if ($company) {
         $response['data']['company_name'] = $company->name;
     }
     $response['remoteComboTexts']['holidayset'] = \GO::t($user->holidayset);
     return parent::loadSettings($settingsController, $params, $response, $user);
 }
예제 #3
0
 protected function beforeSubmit(&$response, &$model, &$params)
 {
     if (!empty($params['permissions'])) {
         $permArr = json_decode($params['permissions']);
         foreach ($permArr as $modPermissions) {
             $modModel = \GO\Base\Model\Module::model()->findByPk($modPermissions->id);
             $modModel->acl->addGroup($params['id'], $modPermissions->permissionLevel);
         }
     }
     return parent::beforeSubmit($response, $model, $params);
 }
예제 #4
0
 /**
  * Render JSON output that can be used by ExtJS GridPanel
  * @param array $params the $_REQUEST params
  */
 protected function actionUsers($module)
 {
     //Create ColumnModel from model
     $columnModel = new ColumnModel(Module::model());
     $columnModel->formatColumn('checked', '\\GO::scriptCanBeDecoded() && \\GO\\Professional\\License::userHasModule($model->username, $module, true)', array('module' => $module));
     $findParams = FindParams::newInstance()->select('t.first_name,t.middle_name,t.last_name,t.username')->ignoreAcl()->limit(0);
     //Create store
     $store = new DbStore('GO\\Base\\Model\\User', $columnModel, $_POST, $findParams);
     $store->defaultSort = 'username';
     $response = $this->renderStore($store);
     $props = \GO::scriptCanBeDecoded() ? \GO\Professional\License::properties() : array();
     $response['license_id'] = isset($props['licenseid']) ? $props['licenseid'] : 0;
     $response['hostname'] = $_SERVER['HTTP_HOST'];
     echo $response;
 }
예제 #5
0
 /**
  * Get the module object to which this controller belongs.
  * Returns false if it's a core controller.
  * 
  * @return Module 
  */
 public function getModule()
 {
     if (!isset($this->_module)) {
         $classParts = explode("\\", get_class($this));
         $moduleId = strtolower($classParts[1]);
         $this->_module = $moduleId == 'core' ? false : Module::model()->findByPk($moduleId, false, true);
     }
     return $this->_module;
 }
예제 #6
0
 public function actionUpdateModuleModel($id = false)
 {
     $response = array();
     if ($id && GO::request()->isPost()) {
         $postData = GO::request()->post['module'];
         $module = Module::model()->findByPk($postData['id']);
         if ($module) {
             // For now only set the sort_order, other attributes can be added later.
             $module->sort_order = $postData['sort_order'];
             if ($module->save()) {
                 $response['success'] = true;
             } else {
                 $response['success'] = false;
                 $response['feedback'] = sprintf(\GO::t('validationErrorsFound'), strtolower($module->localizedName)) . "\n\n" . implode("\n", $module->getValidationErrors()) . "\n";
                 $response['validationErrors'] = $module->getValidationErrors();
             }
         }
     } else {
         $response['success'] = false;
         $response['feedback'] = 'NO MODULE FOUND';
     }
     echo new \GO\Base\Data\JsonResponse($response);
 }
예제 #7
0
 protected function afterSubmit(&$response, &$model, &$params, $modifiedAttributes)
 {
     //Save the contact fields to the contact.
     $contact = $model->createContact();
     if ($contact) {
         unset($params['id']);
         //if user typed in a new company name manually we set this attribute so a new company will be autocreated.
         if (!is_numeric($params['company_id'])) {
             $contact->company_name = $params['company_id'];
         }
         $contact->setAttributes($params);
         $contact->save();
     }
     if (isset($_POST['modules'])) {
         $modules = !empty($_POST['modules']) ? json_decode($_POST['modules']) : array();
         $groupsMember = json_decode($_POST['group_member'], true);
         $groupsVisible = json_decode($_POST['groups_visible'], true);
         /**
          * Process selected module permissions
          */
         foreach ($modules as $modPermissions) {
             $modModel = \GO\Base\Model\Module::model()->findByPk($modPermissions->id);
             $modModel->acl->addUser($model->id, $modPermissions->permissionLevel);
         }
         /**
          * User will be member of the selected groups
          */
         foreach ($groupsMember as $group) {
             if ($group['id'] != \GO::config()->group_everyone) {
                 if ($group['selected']) {
                     \GO\Base\Model\Group::model()->findByPk($group['id'])->addUser($model->id);
                 } else {
                     \GO\Base\Model\Group::model()->findByPk($group['id'])->removeUser($model->id);
                 }
             }
         }
         /**
          * User will be visible to the selected groups
          */
         foreach ($groupsVisible as $group) {
             if ($group['selected']) {
                 $model->acl->addGroup($group['id'], \GO\Base\Model\Acl::MANAGE_PERMISSION);
             } else {
                 $model->acl->removeGroup($group['id']);
             }
         }
     }
     $model->checkDefaultModels();
     if (!empty($params['send_invitation'])) {
         $model->sendRegistrationMail();
     }
 }