Exemple #1
0
 public static function create($field_name, $structure, $module)
 {
     $field = new __cms_field();
     $field->do_retrieve([], ['where_equals' => ['mid' => $module, 'field_name' => $field_name]]);
     if (!$field->get_primary_key()) {
         $field->field_name = $field_name;
         $field->mid = $module;
         $field->type = $structure->type;
         $field->title = isset($structure->title) ? $structure->title : ucwords(str_replace('_', ' ', $field_name));
         if (isset($structure->module) && $structure->module) {
             $_module = new __cms_module();
             $_module->do_retrieve(['mid'], ['where_equals' => ['table_name' => $structure->module]]);
             $field->link_module = $_module->mid;
             if (isset($structure->field) && $structure->field) {
                 $_field = new __cms_field();
                 $_field->do_retrieve(['fid'], ['where_equals' => ['field_name' => $structure->field, 'mid' => $_module->mid]]);
                 if ($_field->get_primary_key()) {
                     $field->link_field = $_field->fid;
                 }
             }
         }
         $field->list = isset($structure->list) ? $structure->list : true;
         $field->filter = isset($structure->filter) ? $structure->filter : true;
         $field->required = isset($structure->required) ? $structure->required : true;
         $field->do_save();
     } else {
         throw new \Exception('Field ' . $field_name . ' already exists in module ' . $module);
     }
     return $field;
 }
 public function do_submit($no_session = false)
 {
     if (!$no_session) {
         foreach ($this->fields as $field) {
             if ($field instanceof field_boolean && !$this->{$field->field_name}) {
                 session::un_set('cms', 'filter', $this->_mid, $field->field_name);
             } else {
                 session::set($this->{$field->field_name}, 'cms', 'filter', $this->_mid, $field->field_name);
             }
         }
     }
     $module = new _cms_module();
     $module->do_retrieve([], ['where_equals' => ['mid' => $this->_mid]]);
     $list = new _cms_table_list($module, 1);
     ajax::update($list->get_table());
 }
Exemple #3
0
 public static function create_table_join($source, $destination)
 {
     $source_module = new _cms_module();
     $source_module->do_retrieve(['primary_key'], ['where_equals' => ['table_name' => $source]]);
     $destination_module = new _cms_module();
     $destination_module->do_retrieve(['primary_key'], ['where_equals' => ['table_name' => $destination]]);
     $sql = 'CREATE TABLE IF NOT EXISTS ' . $source . '_link_' . $destination . '
         (
             `' . $source_module->primary_key . '` INT(6) NOT NULL DEFAULT 0,
             `link_' . $destination_module->primary_key . '` INT(6) NOT NULL DEFAULT 0,
             `fid` INT(6) NOT NULL DEFAULT 0,
             INDEX(`' . $source_module->primary_key . '`,`link_' . $destination_module->primary_key . '`,`fid`),
             INDEX(`link_' . $destination_module->primary_key . '`)
         )
     ';
     $setting_strings = [];
     foreach (_db::$default_table_settings as $setting => $value) {
         if (is_numeric($setting)) {
             $setting_strings[] = $value;
         } else {
             $setting_strings[] = $setting . ' = ' . $value;
         }
     }
     $sql .= implode(',', $setting_strings);
     _db::query($sql);
 }
Exemple #4
0
 /** Add user level management
  * ---CMS User
  * ---CMS User level
  * ---CMS User --> CMS Module
  * */
 public function patch_v4()
 {
     if (!db::table_exists('_cms_user')) {
         self::create_from_structure('_cms_user');
         table::reload_table_definitions();
         $user_level = new _cms_user_level();
         $user_level->title = 'User';
         $user_level->do_save();
         $user_level->ulid = 0;
         $user_level->title = 'Webmaster';
         $user_level->do_save();
         $user_level->ulid = 0;
         $user_level->title = 'Admin';
         $user_level->do_save();
         $cms_user = new _cms_user();
         $cms_user->title = 'admin';
         $cms_user->password = '******';
         $cms_user->ulid = 3;
         $cms_user->do_save();
         $_module = new _cms_module();
         $_module->do_retrieve([], ['where_equals' => ['table_name' => '_cms_module']]);
         $_field = new _cms_field();
         $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_view']]);
         static::modify_link_field($_field, '_cms_user_level', 'title');
         $_field = new _cms_field();
         $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_add']]);
         static::modify_link_field($_field, '_cms_user_level', 'title');
         $_field = new _cms_field();
         $_field->do_retrieve([], ['where_equals' => ['mid' => $_module->get_primary_key(), 'field_name' => 'user_level_delete']]);
         static::modify_link_field($_field, '_cms_user_level', 'title');
     }
 }
Exemple #5
0
 public function do_toggle_expand()
 {
     if (isset($_REQUEST['id'])) {
         $module = new _cms_module();
         $module->do_retrieve([], ['where_equals' => ['mid' => $_REQUEST['mid']]]);
         if (_session::is_set('cms', 'expand', $module->mid)) {
             $value = _session::get('cms', 'expand', $module->mid);
             if (($key = array_search($_REQUEST['id'], $value)) !== false) {
                 unset($value[$key]);
             } else {
                 $value[] = $_REQUEST['id'];
             }
             _session::set($value, 'cms', 'expand', $module->mid);
         } else {
             _session::set([$_REQUEST['id']], 'cms', 'expand', $module->mid);
         }
         $list = new _cms_table_list($module, 1);
         _ajax::update($list->get_table());
     }
 }