Ejemplo n.º 1
0
 /**
  * [permListFill description]
  * @param  boolean $_fill [description]
  * @return [type]         [description]
  */
 public static function permListFill($_fill = false)
 {
     $permResult = [];
     $permCond = ['view', 'add', 'edit', 'delete', 'admin'];
     foreach (\lib\utility\option::contentList() as $myContent) {
         // for superusers allow access
         if ($_fill === "su") {
             $permResult[$myContent]['enable'] = true;
         } elseif ($_fill) {
             // step1: get and fill content enable status
             $postValue = \lib\utility::post('content-' . $myContent);
             if ($postValue === 'on') {
                 $permResult[$myContent]['enable'] = true;
             } else {
                 $permResult[$myContent]['enable'] = false;
             }
         } else {
             $permResult[$myContent]['enable'] = null;
         }
         // step2: fill content modules status
         foreach (self::moduleList($myContent) as $myLoc => $value) {
             foreach ($permCond as $cond) {
                 // for superusers allow access
                 if ($_fill === "su") {
                     $permResult[$myContent]['modules'][$myLoc][$cond] = true;
                 } elseif ($_fill) {
                     $locName = $myContent . '-' . $myLoc . '-' . $cond;
                     $postValue = \lib\utility::post($locName);
                     if ($postValue === 'on') {
                         $permResult[$myContent]['modules'][$myLoc][$cond] = true;
                     }
                     // else
                     // {
                     // $permResult[$myContent]['modules'][$myLoc][$cond] = null;
                     // }
                 } else {
                     $permResult[$myContent]['modules'][$myLoc][$cond] = null;
                 }
             }
         }
     }
     return $permResult;
 }
Ejemplo n.º 2
0
 /**
  * read permission data and fill in array
  * @param  [type] $_list [description]
  * @return [type]        [description]
  */
 public function permModuleFill()
 {
     $permResult = [];
     // 1. get the name of permission
     $myChild = $this->child();
     if ($myChild === 'edit') {
         $myChild = $this->childparam('edit');
     }
     // 2. get perm data from table
     $qry = $this->sql()->table('options')->where('user_id', 'IS', 'NULL')->and('post_id', 'IS', "NULL")->and('option_cat', 'permissions')->and('option_value', $myChild)->and('option_status', "enable");
     $datarow = $qry->select()->assoc('option_meta');
     if (substr($datarow, 0, 1) == '{') {
         $datarow = json_decode($datarow, true);
     }
     // 3. fill the result
     foreach (\lib\utility\option::contentList() as $myContent) {
         // 3.1 fill null
         $permResult[$myContent] = ['enable' => null, 'modules' => null, 'roles' => null];
         // 3.2 set enable status
         if (isset($datarow[$myContent]['enable']) && $datarow[$myContent]['enable']) {
             $permResult[$myContent]['enable'] = true;
         }
         // 3.3 get modules list of specefic content and fill it with db values
         foreach (\lib\utility\permission::moduleList($myContent) as $myLoc => $value) {
             if (isset($datarow[$myContent]['modules'][$myLoc]) && is_array($datarow[$myContent]['modules'][$myLoc])) {
                 $permResult[$myContent]['modules'][$myLoc] = $datarow[$myContent]['modules'][$myLoc];
                 // if user set specefic value for this location add it to db values
                 if (is_array($value)) {
                     $permResult[$myContent]['modules'][$myLoc] += $value;
                 }
             } else {
                 $permResult[$myContent]['modules'][$myLoc] = $value;
             }
         }
     }
     return $permResult;
 }
Ejemplo n.º 3
0
 function view_datatable()
 {
     $form_general = $this->createform('.options', 'general', true);
     $form_config = $this->createform('.options', 'config', true);
     $form_social = $this->createform('.options', 'social', true);
     $form_twitter = $this->createform('.options', 'twitter', true);
     $form_facebook = $this->createform('.options', 'facebook', true);
     $form_telegram = $this->createform('.options', 'telegram', true);
     $form_sms = $this->createform('.options', 'sms', true);
     $form_register = $this->createform('.options', 'account', true);
     // add languages item
     foreach (\lib\utility\option::languages() as $key => $value) {
         $form_config->config_defaultLang->child()->id('lang_' . $key)->value($key)->label($value);
     }
     // add sms items
     $form_sms->sms_name->child()->id('sms_kavenegar')->value('kavenegar_api')->label(T_('Kavenegar'));
     $tld_list = ['com', 'org', 'edu', 'net', 'ir'];
     foreach ($tld_list as $key => $tld) {
         $form_config->config_defaultTld->child()->id('config_tld_' . $tld)->value($tld)->label($tld);
     }
     // add content list to show for redirect
     foreach (\lib\utility\option::contentList(true) as $key => $value) {
         $form_register->account_redirect->child()->id('redirect_' . $key)->value($value)->label(T_($value));
     }
     // give perm list and fill it in default register type
     $myPermList = $form_register->account_default;
     $myPermNames = \lib\utility\option::permList();
     if (!$myPermNames) {
         $myPermNames = [];
     }
     $myPerm = 1;
     // if list of permission is more than 6 item show in select
     if (count($myPermNames) > 6) {
         $myPermList = $form_register->account_default->type('select');
     }
     // get list of permissions
     foreach ($myPermNames as $key => $value) {
         if ($myPerm == $key) {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm_' . $key)->selected();
         } else {
             $myPermList->child()->value($key)->label(T_($value))->elname(null)->pl(null)->attr('type', null)->id('perm_' . $key);
         }
     }
     // get the datatable of options
     $datatable = $this->model()->draw_options();
     // $datatable['sms']['sms'] = null;
     // fill all forms used in options page
     if (isset($datatable['general'])) {
         $this->form_fill($form_general, $datatable['general']);
     }
     if (isset($datatable['config']['config'])) {
         $this->form_fill($form_config, $datatable['config']['config']);
         // add default tld to domain name
         if (isset($datatable['config']['config']['meta']['defaultTld'])) {
             $selectedTld = $datatable['config']['config']['meta']['defaultTld'];
             $form_config->config_domainName->attr('data-after', $selectedTld);
         }
     }
     if (isset($datatable['social'])) {
         $this->form_fill($form_social, $datatable['social']);
     }
     if (isset($datatable['social']['twitter'])) {
         $this->form_fill($form_twitter, $datatable['social']['twitter']);
     }
     if (isset($datatable['social']['facebook'])) {
         $this->form_fill($form_facebook, $datatable['social']['facebook']);
     }
     if (isset($datatable['social']['telegram'])) {
         $this->form_fill($form_telegram, $datatable['social']['telegram']);
     }
     if (isset($datatable['sms']['sms'])) {
         $this->form_fill($form_sms, $datatable['sms']['sms']);
     }
     if (isset($datatable['account']['account'])) {
         $this->form_fill($form_register, $datatable['account']['account']);
     }
 }