Esempio n. 1
0
 public function showMainFilePerm()
 {
     // the primary key of the row that was clicked is available in the 'item' url parameter.
     $pk = $_GET['item'];
     $mf = ManagedfileQuery::create()->findPk($pk);
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('oread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('owner'))), 'owrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('owner'))), 'rread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('role'))), 'rwrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('role'))), 'wread' => array('checkbox', array('label' => 'Read', 'value' => $mf->getReadPerm('world'))), 'wwrite' => array('checkbox', array('label' => 'Write', 'value' => $mf->getWritePerm('world'))))));
     $form->addDisplayGroup(array('oread', 'owrite'), 'grpOwner', array('legend' => 'Owner permissions'));
     $form->addDisplayGroup(array('rread', 'rwrite'), 'grpRole', array('legend' => 'Role permissions'));
     $form->addDisplayGroup(array('wread', 'wwrite'), 'grpWorld', array('legend' => 'World permissions'));
     $form->addElement('submit', 'save', array('label' => 'Update permisisons'));
     if (isPost() && $form->isValid($_POST)) {
         $values = $form->getValues();
         $operm = array('read' => (bool) $values['oread'], 'write' => (bool) $values['owrite']);
         $rperm = array('read' => (bool) $values['rread'], 'write' => (bool) $values['rwrite']);
         $wperm = array('read' => (bool) $values['wread'], 'write' => (bool) $values['wwrite']);
         $mf->setPermission(Managedfile::getPermissionWord($operm, $rperm, $wperm))->save();
         $this->createModelUpdateEvent('Managedfile', $mf->getPrimaryKey(), 'update');
         return '';
     }
     $this->addMainContent($form);
 }
Esempio n. 2
0
 /**
  * Edit module form.
  *
  * @param PageModuleWrapper $wrapper
  * @return Curry_Form|null
  */
 protected function getModuleForm(PageModuleWrapper $wrapper)
 {
     $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'elements' => array('pid_editmodule' => array('hidden'))));
     if ($wrapper->hasData()) {
         $subform = $wrapper->createObject()->showBack();
         if ($subform == null) {
             return null;
         }
         if (!$subform instanceof Curry_Form_SubForm) {
             throw new Exception($wrapper->getClassName() . '::showBack() did not return an instance of Curry_Form_SubForm.');
         }
         if (!$subform->getLegend()) {
             $subform->setLegend($wrapper->getName() . ' (' . $wrapper->getClassName() . ')');
         }
         if (!$subform instanceof Curry_Form_MultiForm) {
             $subform->setDecorators(array('FormElements'));
         }
         $form->addSubForm($subform, 'module' . $wrapper->getPageModuleId());
         $buttons = array('save');
         $form->addElement('submit', 'save', array('label' => 'Save'));
         if ($wrapper->isDeletable()) {
             $form->addElement('submit', 'delete', array('label' => 'Remove content'));
             $buttons[] = 'delete';
         }
         $form->addDisplayGroup($buttons, 'dg1', array('class' => 'horizontal-group'));
     } else {
         $form->addElement('submit', 'create', array('label' => $wrapper->isInherited() ? 'Override content' : 'Create content'));
     }
     return $form;
 }
Esempio n. 3
0
 protected function getDatabaseForm($params)
 {
     $pdoDrivers = method_exists('PDO', 'getAvailableDrivers') ? PDO::getAvailableDrivers() : array();
     $adapters = count($pdoDrivers) ? array_combine($pdoDrivers, $pdoDrivers) : array();
     $form = new Curry_Form(array('csrfCheck' => false, 'elements' => array('adapter' => array('select', array('label' => 'Adapter', 'multiOptions' => $adapters)), 'host' => array('text', array('label' => 'Host', 'value' => $params['host'])), 'database' => array('text', array('label' => 'Database', 'value' => $params['database'])), 'user' => array('text', array('label' => 'User', 'value' => $params['user'])), 'password' => array('password', array('label' => 'Password', 'renderPassword' => true, 'value' => $params['password'])), 'set_charset' => array('checkbox', array('label' => 'Set database charset to UTF-8', 'value' => $params['set_charset'])), 'create_tables' => array('checkbox', array('label' => 'Create tables', 'value' => $params['create_tables'])), 'test' => array('submit', array('label' => 'Test connection')), 'save' => array('submit', array('label' => 'Save')))));
     $form->addDisplayGroup(array('test', 'save'), 'buttons', array('class' => 'horizontal-group'));
     return $form;
 }
Esempio n. 4
0
 /**
  * Import data into table from CSV file.
  *
  * @todo Add support for propel advanced columns (array).
  *
  * @throws Exception
  */
 public function showImport()
 {
     $modelClass = $_GET['table'];
     $tableMap = PropelQuery::from($modelClass)->getTableMap();
     $columnOptions = Curry_Array::objectsToArray($tableMap->getColumns(), 'getName', 'getPhpName');
     $pks = array();
     foreach ($tableMap->getColumns() as $column) {
         if ($column->isPrimaryKey()) {
             $pks[] = $column->getName();
         }
     }
     $form = new Curry_Form(array('method' => 'post', 'action' => url('', $_GET), 'elements' => array('file' => array('file', array('label' => 'CSV File', 'valueDisabled' => true)), 'mode' => array('select', array('label' => 'Mode', 'multiOptions' => array(self::IMPORT_REPLACE => 'Replace', self::IMPORT_APPEND => 'Append', self::IMPORT_UPDATE => 'Update', self::IMPORT_UPDATE_OR_INSERT => 'Update or insert'))), 'skip_first' => array('checkbox', array('label' => 'Skip first line', 'value' => true)), 'columns' => array('text', array('label' => 'Columns in file', 'value' => join(',', array_keys($columnOptions)))), 'use_columns' => array('multiselect', array('label' => 'Columns to use', 'multiOptions' => $columnOptions, 'value' => array_keys($columnOptions), 'size' => min(10, count($columnOptions)))), 'delimiter' => array('text', array('label' => 'Delimiter', 'value' => ',')), 'enclosure' => array('text', array('label' => 'Enclosure', 'value' => '"')), 'escape' => array('text', array('label' => 'Escape', 'value' => '\\')), 'null_value' => array('text', array('label' => 'Null', 'value' => 'Ø')), 'submit' => array('submit', array('label' => 'Import')))));
     $fields = array_slice(array_keys($form->getElements()), 2, -1);
     $form->addDisplayGroup($fields, 'advanced', array('legend' => 'Advanced options', 'class' => 'advanced', 'order' => 2));
     $this->addMainContent('<h2>Import: ' . htmlspecialchars($modelClass) . '</h2>');
     if (isPost() && $form->isValid($_POST)) {
         $mode = $form->mode->getValue();
         $skipFirst = $form->skip_first->getValue();
         $columns = explode(',', $form->columns->getValue());
         $useColumns = $form->use_columns->getValue();
         $delimiter = $form->delimiter->getValue();
         $enclosure = $form->enclosure->getValue();
         $escape = $form->escape->getValue();
         $nullValue = $form->null_value->getValue();
         if (!$form->file->isUploaded()) {
             throw new Exception('Error when uploading file.');
         }
         // Check for non-existent columns
         $nonExistent = array_filter(array_diff($columns, array_keys($columnOptions)));
         if (count($nonExistent)) {
             throw new Exception('Unknown column in column list: ' . join(', ', $nonExistent));
         }
         // Open csv file
         $fileInfo = $form->file->getFileInfo();
         $fp = fopen($fileInfo['file']['tmp_name'], "r");
         if (!$fp) {
             throw new Exception('Unable to open file');
         }
         // Wrap in transaction
         $deleted = 0;
         $updated = 0;
         $inserted = 0;
         $con = Propel::getConnection(PropelQuery::from($modelClass)->getDbName());
         $con->beginTransaction();
         try {
             // Replace will empty the table
             if ($mode === self::IMPORT_REPLACE) {
                 $deleted = PropelQuery::from($modelClass)->deleteAll();
             }
             // Read csv lines
             while (($data = fgetcsv($fp, 0, $delimiter, $enclosure, $escape)) !== false) {
                 if (count($data) !== count($columns)) {
                     throw new Exception('Invalid column count ' . count($data) . ', expected ' . count($columns));
                 }
                 if ($skipFirst) {
                     $skipFirst = false;
                     continue;
                 }
                 $data = array_combine($columns, $data);
                 $pkData = array();
                 // Check for null values and collect primary key
                 foreach ($data as $k => $v) {
                     if ($v === $nullValue) {
                         $data[$k] = $v = null;
                     }
                     if (in_array($k, $pks)) {
                         $pkData[$k] = $v;
                     }
                 }
                 $obj = null;
                 if ($mode === self::IMPORT_UPDATE || $mode === self::IMPORT_UPDATE_OR_INSERT) {
                     // attempt to find existing object using pk
                     if (count($pkData) === count($pks)) {
                         $obj = new $modelClass();
                         $obj->fromArray($pkData, BasePeer::TYPE_FIELDNAME);
                         $obj = PropelQuery::from($modelClass)->findPk($obj->getPrimaryKey());
                     }
                     if (!$obj && $mode === self::IMPORT_UPDATE_OR_INSERT) {
                         // not found, create new
                         $obj = new $modelClass();
                     }
                 } else {
                     // REPLACE, APPEND
                     $obj = new $modelClass();
                 }
                 // Remove unused columns
                 foreach ($data as $k => $v) {
                     if (!in_array($k, $useColumns)) {
                         unset($data[$k]);
                     }
                 }
                 if ($obj) {
                     // Unset primary key columns in data when appending
                     if ($mode === self::IMPORT_APPEND) {
                         foreach ($pks as $pk) {
                             if (array_key_exists($pk, $data)) {
                                 unset($data[$pk]);
                             }
                         }
                     }
                     $obj->fromArray($data, BasePeer::TYPE_FIELDNAME);
                     if ($obj->isNew()) {
                         // allows insert of custom primary key
                         BasePeer::doInsert($obj->buildCriteria(), $con);
                         ++$inserted;
                     } else {
                         $updated += $obj->save();
                     }
                 }
             }
             $con->commit();
         } catch (Exception $e) {
             $con->rollBack();
             throw $e;
         }
         if ($deleted) {
             $this->addMessage('Deleted: ' . $deleted);
         }
         if ($inserted) {
             $this->addMessage('Inserted: ' . $inserted);
         }
         if ($updated) {
             $this->addMessage('Updated: ' . $updated);
         }
         $this->addMessage('All done.', self::MSG_SUCCESS);
     } else {
         $this->addMainContent($form);
     }
 }
Esempio n. 5
0
 /**
  * Create new module form.
  *
  * @param PageRevision $pageRevision
  * @param string $moduleClass
  * @return Curry_Form
  */
 public static function getNewModuleForm($pageRevision, $moduleClass, $target)
 {
     $valid = array();
     $modules = array();
     foreach (ModuleQuery::create()->orderByTitle()->find() as $module) {
         $inTargets = in_array($target, $module->getTargets());
         if (!$target || ($module->getTargetsExclude() ? !$inTargets : $inTargets)) {
             $modules[$module->getModuleId()] = $module->getTitle();
             $valid[] = $module->getModuleId();
         }
     }
     $user = User::getUser();
     $modulePermission = $user->hasPagePermission($pageRevision->getPage(), PageAccessPeer::PERM_MODULES);
     if ($modulePermission) {
         $modules = array('Predefined' => $modules);
         foreach (AbstractModule::getModuleList() as $className) {
             $parts = explode("_", str_replace("_Module_", "_", $className));
             $package = array_shift($parts);
             $modules[$package][$className] = join(" / ", $parts);
             $valid[] = $className;
         }
     }
     if (!$moduleClass || !in_array($moduleClass, $valid)) {
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('module_class' => array('select', array('label' => 'Type', 'multiOptions' => $modules, 'required' => true)), 'next' => array('submit', array('label' => 'Next')))));
         return $form;
     } else {
         // Fetch template targets
         $targets = array();
         try {
             $template = $pageRevision->getInheritedProperty('Template');
             if ($template) {
                 $template = \Curry\App::getInstance()->twig->loadTemplate($template);
             }
             while ($template) {
                 $targets = array_merge($targets, $template->getPlaceholders());
                 $template = $template->getParent(array());
             }
         } catch (Exception $e) {
             \Curry\App::getInstance()->logger->warning('Error in template: ' . $e->getMessage());
         }
         if (count($targets)) {
             $targets = array_combine(array_values($targets), array_values($targets));
         }
         // Check for predefined module creation
         if (ctype_digit($moduleClass)) {
             $module = ModuleQuery::create()->findPk($moduleClass);
             $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden', array('value' => 1)), 'module_class' => array('hidden', array('value' => $moduleClass)), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $module->getName())))));
             if (!$target) {
                 // Show only acceptable targets...
                 $form->addElement('select', 'target', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'multiOptions' => $targets));
             } else {
                 $form->addElement('hidden', 'target', array('value' => $target));
                 $form->setCsrfCheck(false);
                 $_POST = $form->getValues();
             }
             $form->addElement('submit', 'add', array('label' => 'Add module'));
             return $form;
         }
         if (!class_exists($moduleClass)) {
             throw new Exception('Class \'' . $moduleClass . '\' could not be loaded, please check the path and classname.');
         }
         $defaultName = substr($moduleClass, strrpos($moduleClass, '_') + 1);
         $targets[''] = '[ Custom ]';
         asort($targets);
         $templates = array('' => "[ None ]", 'new' => "[ Create new ]") + Curry_Backend_Template::getTemplateSelect();
         $defaultTemplateName = 'Modules/' . $defaultName . '.html';
         $defaultTemplate = '';
         if ($moduleClass !== 'Curry_Module_Article' && call_user_func(array($moduleClass, 'hasTemplate'))) {
             $defaultTemplate = array_key_exists($defaultTemplateName, $templates) ? $defaultTemplateName : 'new';
         }
         $predefinedTemplates = call_user_func(array($moduleClass, 'getPredefinedTemplates'));
         $predefinedTemplates = count($predefinedTemplates) ? array_combine(array_keys($predefinedTemplates), array_keys($predefinedTemplates)) : array();
         $predefinedTemplates = array('' => '[ Empty ]') + $predefinedTemplates;
         $form = new Curry_Form(array('action' => url('', $_GET), 'method' => 'post', 'class' => isAjax() ? 'dialog-form' : '', 'elements' => array('pid_newmodule' => array('hidden'), 'module_class' => array('hidden', array('value' => $moduleClass)), 'module_class_display' => array('rawHtml', array('label' => 'Type', 'value' => '<input type="text" value="' . $moduleClass . '" disabled="disabled" />')), 'name' => array('text', array('label' => 'Name', 'required' => true, 'description' => 'A descriptive name of the module.', 'value' => $defaultName)), 'target' => array('select', array('label' => 'Target', 'description' => 'Specifies what placeholder/variable in the page-template to attach this module to.', 'value' => isset($_GET['target']) ? $_GET['target'] : null, 'multiOptions' => $targets, 'class' => 'trigger-change', 'onchange' => "\$('#target_name-label, #target_name-element').toggle(\$(this).val() == '');")), 'target_name' => array('text', array('label' => 'Target Name')), 'template' => array('select', array('class' => 'trigger-change', 'label' => 'Template', 'multiOptions' => $templates, 'value' => $defaultTemplate, 'onchange' => "\$('#template_name-label, #template_name-element, #predefined_template-label, #predefined_template-element').toggle(\$(this).val() == 'new');")), 'template_name' => array('text', array('label' => 'Name', 'value' => $defaultTemplateName)), 'predefined_template' => array('select', array('label' => 'Predefined template', 'multiOptions' => $predefinedTemplates)), 'content_visibility' => array('select', array('label' => 'Content Visibility', 'description' => 'Set the visibility of this module in the Content backend module.', 'multiOptions' => PageModulePeer::$contentVisiblityOptions, 'value' => PageModulePeer::CONTENT_VISIBILITY_ALWAYS, 'required' => true)), 'search_visibility' => array('checkbox', array('label' => 'Search Visibility', 'description' => 'If this module should be rendered when indexing pages.', 'value' => true, 'required' => true)))));
         $form->addDisplayGroup(array('position', 'content_visibility', 'search_visibility'), 'advanced', array('class' => 'advanced', 'legend' => 'Advanced'));
         $form->addElement('submit', 'add', array('label' => 'Add module'));
     }
     return $form;
 }