public function ajaxAddType()
 {
     $app = JFactory::getApplication();
     $client = $app->input->get('client', '');
     $fields = $app->input->getString('fields', '');
     $folder = $app->input->getInt('folder_id', 1);
     $title = $app->input->getString('title', '');
     $type_id = $app->input->getInt('type_id', 0);
     if (!$title) {
         return;
     }
     // -- Type
     require_once JPATH_ADMINISTRATOR . '/components/com_cck/tables/type.php';
     require_once JPATH_ADMINISTRATOR . '/components/com_cck/helpers/helper_workshop.php';
     $style = Helper_Workshop::getDefaultStyle('seb_one');
     $table = JTable::getInstance('type', 'CCK_Table');
     $table->title = $title;
     $table->folder = $folder;
     $table->template_admin = $style->id;
     $table->template_site = $style->id;
     $table->template_content = $style->id;
     $table->template_intro = $style->id;
     $table->published = 1;
     $table->indexed = 'intro';
     $table->storage_location = 'none';
     $rules = array('core.create' => array(), 'core.create.max.parent' => array('8' => "0"), 'core.create.max.parent.author' => array('8' => "0"), 'core.create.max.author' => array('8' => "0"), 'core.delete' => array(), 'core.delete.own' => array(), 'core.edit' => array(), 'core.edit.own' => array());
     $rules = new JAccessRules($rules);
     $table->setRules($rules);
     $table->check();
     $table->store();
     // --
     // -- Field
     require_once JPATH_ADMINISTRATOR . '/components/com_cck/tables/field.php';
     $table2 = JTable::getInstance('field', 'CCK_Table');
     $table2->title = $title;
     $table2->name = $table->name;
     $table2->folder = $folder;
     $table2->type = 'group';
     $table2->published = 1;
     $table2->label = 'clear';
     $table2->display = 3;
     $table2->extended = $table->name;
     $table2->rows = 1;
     $table2->storage = 'none';
     $table2->storage_field = $table->name;
     $table2->check();
     $table2->store();
     // --
     if ($fields && $client && $type_id) {
         $query = 'UPDATE #__cck_core_type_field' . ' SET typeid = ' . (int) $table->id . ', computation = "", computation_options = "", conditional = "", conditional_options = ""' . ' WHERE typeid = ' . $type_id . ' AND client = "' . $client . '" AND fieldid IN (' . $fields . ')';
         JCckDatabase::execute($query);
     }
     if (is_object($table2)) {
         echo $this->ajax_field_li($table2, $client);
     }
 }
예제 #2
0
 public function duplicate($pk)
 {
     $app = JFactory::getApplication();
     $db = $this->getDbo();
     $title = $app->input->getString('duplicate_title', '');
     $user = JFactory::getUser();
     if (!$user->authorise('core.create', COM_CCK)) {
         throw new Exception(JText::_('JERROR_CORE_CREATE_NOT_PERMITTED'));
     }
     $table = $this->getTable();
     $table->load($pk, true);
     if ($table->id) {
         $table->id = 0;
         if ($title) {
             $table->title = $title;
         } else {
             $table->title .= ' (2)';
         }
         $table->name = '';
         if (!$table->check()) {
             throw new Exception($table->getError());
         }
         $prefix = JCck::getConfig_Param('development_prefix', '');
         if ($prefix) {
             $table->name = $prefix . '_' . $table->name;
         }
         // Template Styles
         $clients = array('search', 'filter', 'list', 'item');
         $styles = JCckDatabase::loadObjectList('SELECT * FROM #__template_styles WHERE id IN (' . (int) $table->template_search . ',' . (int) $table->template_filter . ',' . (int) $table->template_list . ',' . (int) $table->template_item . ')', 'id');
         foreach ($clients as $client) {
             $property = 'template_' . $client;
             $style = $styles[$table->{$property}];
             if (!(is_object($style) && $style->id)) {
                 $style = Helper_Workshop::getDefaultStyle($client == 'list' ? 'seb_table' : 'seb_one');
             }
             $table->{$property} = Helper_Workshop::getTemplateStyleInstance($style->id, $style->template, $style->template, $style->params, $table->name . ' (' . $client . ')', true);
         }
         if (!$table->store()) {
             throw new Exception($table->getError());
         }
         if (!$table->id) {
             return 0;
         }
         // Fields
         $query = 'SELECT a.*, b.storage_table FROM #__cck_core_search_field AS a LEFT JOIN #__cck_core_fields AS b ON b.id = a.fieldid WHERE a.searchid = ' . (int) $pk;
         $string = $this->_table_no_key_batch('query', $query, '#__cck_core_search_field', 'searchid', $table->id, array('storage_table'));
         // Positions
         $string = $this->_table_no_key_batch('where', 'searchid = ' . (int) $pk, '#__cck_core_search_position', 'searchid', $table->id);
     }
 }