Exemplo n.º 1
0
 /**
  * Disable/enable a user group
  * @param integer
  * @param boolean
  * @param \DataContainer
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Check permissions to edit
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     $this->checkPermission();
     // Check permissions to publish
     if (!$this->User->hasAccess('tl_product_price::published', 'alexf')) {
         $this->log('Not enough permissions to publish/unpublish price item ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_product_price', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_product_price']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_product_price']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_product_price SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_product_price.id=' . $intId . '" has been created' . $this->getParentEntries('tl_product_price', $intId), __METHOD__, TL_GENERAL);
 }
 /**
  * Disable/enable a user group
  * @param integer
  * @param boolean
  */
 public function toggleVisibility($intId, $blnVisible)
 {
     // Check permissions to edit
     $objInput = \Input::getInstance();
     $objInput->setGet('id', $intId);
     $objInput->setGet('act', 'toggle');
     #$this->checkPermission();
     // Check permissions to publish
     if (!$this->User->isAdmin && !$this->User->hasAccess('tl_glossary_term::published', 'alexf')) {
         $this->log('Not enough permissions to publish/unpublish item ID "' . $intId . '"', 'tl_glossary_term toggleVisibility', TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new \Versions('tl_glossary_term', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_glossary_term']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_glossary_term']['fields']['published']['save_callback'] as $callback) {
             $this->import($callback[0]);
             $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $this);
         }
     }
     // Update the database
     \Database::getInstance()->prepare("UPDATE tl_glossary_term SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_glossary_term.id=' . $intId . '" has been created', 'tl_revolutionslider_slides toggleVisibility()', TL_GENERAL);
 }
 /**
  * Import the default robots.txt
  * @param \DataContainer
  */
 public function importRobotsTxt(\DataContainer $dc)
 {
     if (\Input::get('key') != 'importRobotsTxt') {
         return '';
     }
     if (!file_exists(TL_ROOT . "/" . FILE_ROBOTS_TXT_DEFAULT)) {
         \Message::addError($GLOBALS['TL_LANG']['ERR']['no_robotstxt_default']);
         $this->redirect(str_replace('&key=importRobotsTxt', '', \Environment::get('request')));
     }
     $objVersions = new \Versions($dc->table, \Input::get('id'));
     $objVersions->create();
     $strFileContent = file_get_contents(TL_ROOT . "/" . FILE_ROBOTS_TXT_DEFAULT);
     \Database::getInstance()->prepare("UPDATE " . $dc->table . " SET robotsTxtContent=? WHERE id=?")->execute($strFileContent, \Input::get('id'));
     $this->redirect(str_replace('&key=importRobotsTxt', '', \Environment::get('request')));
 }
Exemplo n.º 4
0
 public function __construct($versions = NULL)
 {
     if ($versions == NULL) {
         $versions = Versions::getVersions();
     }
     $this->versions = $versions;
 }
Exemplo n.º 5
0
 /**
  * Disable/enable a user group
  * @param integer
  * @param boolean
  */
 public function toggleVisibility($intId, $blnVisible)
 {
     // Check permissions
     if (!$this->User->hasAccess('tl_member_group::disable', 'alexf')) {
         $this->log('Not enough permissions to activate/deactivate member group ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_member_group', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_member_group']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_member_group']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_member_group SET tstamp=" . time() . ", disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_member_group.id=' . $intId . '" has been created' . $this->getParentEntries('tl_member_group', $intId), __METHOD__, TL_GENERAL);
 }
Exemplo n.º 6
0
 /**
  * list versions
  *
  * @param resource the SQL result
  * @return string the rendered text
  *
  * @see layouts/layout.php
  **/
 function layout($result)
 {
     global $context;
     // empty list
     if (!SQL::count($result)) {
         $output = array();
         return $output;
     }
     // we return an array of ($url => $attributes)
     $items = array();
     // process all items in the list
     while ($item = SQL::fetch($result)) {
         // initialize variables
         $prefix = $suffix = $icon = '';
         // the url to view this item
         $url = '_' . $item['id'];
         // Versions::get_url($item['id']);
         // version description
         $label = sprintf(i18n::s('edited by %s %s'), ucfirst($item['edit_name']), Skin::build_date($item['edit_date']));
         // command to view this version
         $suffix .= ' ' . Skin::build_link(Versions::get_url($item['id'], 'view'), i18n::s('compare to current version'), 'button');
         // list all components for this item
         $items[$url] = array($prefix, $label, $suffix, 'version', $icon);
     }
     // end of processing
     SQL::free($result);
     return $items;
 }
Exemplo n.º 7
0
 /**
  * Execute AJAX post actions to toggle.
  *
  * @param string         $action
  * @param \DataContainer $dc
  */
 public function executePostActions($action, \DataContainer $dc)
 {
     if ($action !== 'hasteAjaxOperation') {
         return;
     }
     $id = $dc->id = \Input::post('id');
     $currentValue = \Input::post('value');
     $operation = \Input::post('operation');
     $hasteAjaxOperationSettings = $GLOBALS['TL_DCA'][$dc->table]['list']['operations'][$operation]['haste_ajax_operation'];
     if (!isset($hasteAjaxOperationSettings)) {
         return;
     }
     // Check permissions
     if (!$this->checkPermission($dc->table, $hasteAjaxOperationSettings)) {
         \System::log(sprintf('Not enough permissions to toggle field %s::%s', $dc->table, $hasteAjaxOperationSettings['field']), __METHOD__, TL_ERROR);
         \Controller::redirect('contao/main.php?act=error');
     }
     // Initialize versioning
     $versions = new \Versions($dc->table, $id);
     $versions->initialize();
     // Determine next value and icon
     $options = $this->getOptions($hasteAjaxOperationSettings);
     $nextIndex = 0;
     foreach ($options as $k => $option) {
         if ($option['value'] == $currentValue) {
             $nextIndex = $k + 1;
         }
     }
     // Make sure that if $nextIndex does not exist it's the first
     if (!isset($options[$nextIndex])) {
         $nextIndex = 0;
     }
     $value = $options[$nextIndex]['value'];
     $value = $this->executeSaveCallback($dc, $value, $hasteAjaxOperationSettings);
     // Update DB
     \Database::getInstance()->prepare('UPDATE ' . $dc->table . ' SET ' . $hasteAjaxOperationSettings['field'] . '=? WHERE id=?')->execute($value, $id);
     $versions->create();
     if ($GLOBALS['TL_DCA'][$dc->table]['config']['enableVersioning']) {
         \System::log(sprintf('A new version of record "%s.id=%s" has been created', $dc->table, $id), __METHOD__, TL_GENERAL);
     }
     $response = array('nextValue' => $options[$nextIndex]['value'], 'nextIcon' => $options[$nextIndex]['icon']);
     $response = new JsonResponse($response);
     $response->send();
 }
Exemplo n.º 8
0
Arquivo: Post.php Projeto: R-J/elefant
	public static function _publish_queued ($posts) {
		foreach (array_keys ($posts) as $k) {
			if ($posts[$k]->published === 'que') {
				$posts[$k]->published = 'yes';
				$posts[$k]->put ();
				\Versions::add ($posts[$k]);
			}
		}
		return $posts;
	}
Exemplo n.º 9
0
 public static function getAllVersions()
 {
     $versions = array();
     $db = Zend_Registry::get('my_db');
     $v = new Versions($db);
     $result = $v->fetchAll("version_id = " . $id);
     foreach ($result as $row) {
         switch (DB_TYPE) {
             case 'mysql':
                 $version = new Version($row->version_id);
                 break;
             case 'oci8':
                 $version = new Version($row->version_id);
                 break;
         }
         array_push($versions, $version);
     }
     return $versions;
 }
 /**
  * Publish/unpublish rule
  * @param integer
  * @param boolean
  * @param \DataContainer
  */
 public function toggleVisibility($intId, $blnVisible, \DataContainer $dc = null)
 {
     $objVersions = new \Versions('tl_css_class_replacer', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_css_class_replacer']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_css_class_replacer']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $blnVisible = \System::importStatic($callback[0])->{$callback}[1]($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     \Database::getInstance()->prepare("UPDATE tl_css_class_replacer SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     \System::log('A new version of record "tl_css_class_replacer.id=' . $intId . '" has been created', __METHOD__, TL_GENERAL);
 }
Exemplo n.º 11
0
 public static function getAllVersions()
 {
     $versions = array();
     //$db = ZitDBAdapter::getDBAdapter();
     $db = Zend_Registry::get('my_db2');
     $v = new Versions($db);
     $result = $v->fetchAll("active = 1");
     foreach ($result as $row) {
         switch (DB_TYPE) {
             case 'mysql':
                 $version = new Version($row->version_id);
                 break;
             case 'oci8':
                 $version = new Version($row->VERSION_ID);
                 break;
         }
         array_push($versions, $version);
     }
     return $versions;
 }
Exemplo n.º 12
0
 public static function last_version()
 {
     $query = Versions::find(array('order' => 'date DESC', 'limit' => 1));
     $result = $query->getFirst();
     $version = $result->version;
     $array = explode('.', $version);
     $key_terakhir = count($array);
     $key_terakhir = $key_terakhir - 1;
     $array[$key_terakhir] = $array[$key_terakhir] + 1;
     $version_now = implode('.', $array);
     return $version_now;
 }
Exemplo n.º 13
0
 public static function checkVersion($passVer)
 {
     $db = Zend_Registry::get('my_db');
     $versions = new Versions($db);
     $quoted = $db->quote($passVer);
     $result = $versions->fetchAll("active = 1 and version_num = {$quoted}");
     foreach ($result as $row) {
         switch (DB_TYPE) {
             case 'mysql':
                 if ($passVer == $row->version_num) {
                     return true;
                 }
                 break;
             case 'oci8':
                 if ($passVer == $row->VERSION_NUM) {
                     return true;
                 }
                 break;
         }
     }
     return false;
 }
 public function toggleVisibility($intId, $blnVisible)
 {
     $objUser = \BackendUser::getInstance();
     $objDatabase = \Database::getInstance();
     // Check permissions to publish
     if (!$objUser->isAdmin && !$objUser->hasAccess('tl_entity_cleaner::published', 'alexf')) {
         \Controller::log('Not enough permissions to publish/unpublish item ID "' . $intId . '"', 'tl_entity_cleaner toggleVisibility', TL_ERROR);
         \Controller::redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_entity_cleaner', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_entity_cleaner']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_entity_cleaner']['fields']['published']['save_callback'] as $callback) {
             $this->import($callback[0]);
             $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $this);
         }
     }
     // Update the database
     $objDatabase->prepare("UPDATE tl_entity_cleaner SET tstamp=" . time() . ", published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     \Controller::log('A new version of record "tl_entity_cleaner.id=' . $intId . '" has been created' . $this->getParentEntries('tl_entity_cleaner', $intId), 'tl_entity_cleaner toggleVisibility()', TL_GENERAL);
 }
 function deleteAction($version_id, $system_id)
 {
     $versions = Versions::findFirstById($version_id);
     if ($versions != false) {
         if ($versions->delete() == false) {
             echo "Sorry, we can't delete the version right now: \n";
             foreach ($versions->getMessages() as $message) {
                 echo $message, "\n";
             }
         } else {
             $this->flash->success('Delete version Success');
             $this->response->redirect('versions/system/' . $system_id);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Disable/enable a user group
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  *
  * @throws Contao\CoreBundle\Exception\AccessDeniedException
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     // Check the field access
     if (!$this->User->hasAccess('tl_member::disable', 'alexf')) {
         throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to activate/deactivate member ID ' . $intId . '.');
     }
     $objVersions = new Versions('tl_member', $intId);
     $objVersions->initialize();
     // Reverse the logic (members have disabled=1)
     $blnVisible = !$blnVisible;
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_member']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_member']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     $time = time();
     // Update the database
     $this->Database->prepare("UPDATE tl_member SET tstamp={$time}, disable='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     // Remove the session if the user is disabled (see #5353)
     if (!$blnVisible) {
         $this->Database->prepare("DELETE FROM tl_session WHERE name='FE_USER_AUTH' AND pid=?")->execute($intId);
     }
 }
Exemplo n.º 17
0
 /**
  * Disable/enable a user group
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     $this->checkPermission();
     // Check the field access
     if (!$this->User->hasAccess('tl_comments::published', 'alexf')) {
         $this->log('Not enough permissions to publish/unpublish comment ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_comments', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_comments']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_comments']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_comments SET tstamp=" . time() . ", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
 }
Exemplo n.º 18
0
 /**
  * Disable/enable a user group
  *
  * @param integer        $intId
  * @param boolean        $blnVisible
  * @param DataContainer $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     $this->checkPermission();
     // Check the field access
     if (!$this->User->hasAccess('tl_calendar_events::published', 'alexf')) {
         $this->log('Not enough permissions to publish/unpublish event ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_calendar_events', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_calendar_events']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_calendar_events SET tstamp=" . time() . ", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_calendar_events.id=' . $intId . '" has been created' . $this->getParentEntries('tl_calendar_events', $intId), __METHOD__, TL_GENERAL);
     // Update the RSS feed (for some reason it does not work without sleep(1))
     sleep(1);
     $this->import('Calendar');
     $this->Calendar->generateFeedsByCalendar(CURRENT_ID);
 }
Exemplo n.º 19
0
$wp = new Webpage($_GET['page']);
$f = new Form('post', 'admin/edit');
$f->verify_csrf = false;
if ($f->submit()) {
    $wp->id = $_POST['id'];
    $wp->title = $_POST['title'];
    $wp->menu_title = $_POST['menu_title'];
    $wp->window_title = $_POST['window_title'];
    $wp->access = $_POST['access'];
    $wp->layout = $_POST['layout'];
    $wp->description = $_POST['description'];
    $wp->keywords = $_POST['keywords'];
    $wp->body = $_POST['body'];
    $wp->put();
    if (!$wp->error) {
        Versions::add($wp);
        $memcache->delete('_admin_page_' . $_GET['page']);
        $this->add_notification(i18n_get('Page saved.'));
        $_POST['page'] = $_GET['page'];
        $lock->remove();
        $this->hook('admin/edit', $_POST);
        $this->redirect('/' . $_POST['id']);
    }
    $page->title = i18n_get('An Error Occurred');
    echo i18n_get('Error Message') . ': ' . $wp->error;
} else {
    $wp->layouts = admin_get_layouts();
    $wp->failed = $f->failed;
    $wp = $f->merge_values($wp);
    $page->title = i18n_get('Edit Page') . ': ' . $wp->title;
    $page->head = $tpl->render('admin/edit/head', $wp) . $tpl->render('admin/wysiwyg');
Exemplo n.º 20
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->import('FrontendUser', 'User');
     $GLOBALS['TL_LANGUAGE'] = $objPage->language;
     \System::loadLanguageFile('tl_member');
     $this->loadDataContainer('tl_member');
     // Call onload_callback (e.g. to check permissions)
     if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}();
             } elseif (is_callable($callback)) {
                 $callback();
             }
         }
     }
     // Set the template
     if ($this->memberTpl != '') {
         /** @var \FrontendTemplate|object $objTemplate */
         $objTemplate = new \FrontendTemplate($this->memberTpl);
         $this->Template = $objTemplate;
         $this->Template->setData($this->arrData);
     }
     $this->Template->fields = '';
     $this->Template->tableless = $this->tableless;
     $arrFields = array();
     $doNotSubmit = false;
     $hasUpload = false;
     $row = 0;
     // Predefine the group order (other groups will be appended automatically)
     $arrGroups = array('personal' => array(), 'address' => array(), 'contact' => array(), 'login' => array(), 'profile' => array());
     $blnModified = false;
     $objMember = \MemberModel::findByPk($this->User->id);
     $strTable = $objMember->getTable();
     // Initialize the versioning (see #7415)
     $objVersions = new \Versions($strTable, $objMember->id);
     $objVersions->setUsername($objMember->username);
     $objVersions->setUserId(0);
     $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1');
     $objVersions->initialize();
     // Build the form
     foreach ($this->editable as $field) {
         $arrData =& $GLOBALS['TL_DCA']['tl_member']['fields'][$field];
         // Map checkboxWizards to regular checkbox widgets
         if ($arrData['inputType'] == 'checkboxWizard') {
             $arrData['inputType'] = 'checkbox';
         }
         // Map fileTrees to upload widgets (see #8091)
         if ($arrData['inputType'] == 'fileTree') {
             $arrData['inputType'] = 'upload';
         }
         /** @var \Widget $strClass */
         $strClass = $GLOBALS['TL_FFL'][$arrData['inputType']];
         // Continue if the class does not exist
         if (!$arrData['eval']['feEditable'] || !class_exists($strClass)) {
             continue;
         }
         $strGroup = $arrData['eval']['feGroup'];
         $arrData['eval']['required'] = false;
         $arrData['eval']['tableless'] = $this->tableless;
         // Use strlen() here (see #3277)
         if ($arrData['eval']['mandatory']) {
             if (is_array($this->User->{$field})) {
                 if (empty($this->User->{$field})) {
                     $arrData['eval']['required'] = true;
                 }
             } else {
                 if (!strlen($this->User->{$field})) {
                     $arrData['eval']['required'] = true;
                 }
             }
         }
         $varValue = $this->User->{$field};
         // Call the load_callback
         if (isset($arrData['load_callback']) && is_array($arrData['load_callback'])) {
             foreach ($arrData['load_callback'] as $callback) {
                 if (is_array($callback)) {
                     $this->import($callback[0]);
                     $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this->User, $this);
                 } elseif (is_callable($callback)) {
                     $varValue = $callback($varValue, $this->User, $this);
                 }
             }
         }
         /** @var \Widget $objWidget */
         $objWidget = new $strClass($strClass::getAttributesFromDca($arrData, $field, $varValue, $field, $strTable, $this));
         $objWidget->storeValues = true;
         $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd');
         // Increase the row count if it is a password field
         if ($objWidget instanceof \FormPassword) {
             if ($objMember->password != '') {
                 $objWidget->mandatory = false;
             }
             $objWidget->rowClassConfirm = 'row_' . ++$row . ($row % 2 == 0 ? ' even' : ' odd');
         }
         // Validate the form data
         if (\Input::post('FORM_SUBMIT') == 'tl_member_' . $this->id) {
             $objWidget->validate();
             $varValue = $objWidget->value;
             $rgxp = $arrData['eval']['rgxp'];
             // Convert date formats into timestamps (check the eval setting first -> #3063)
             if ($varValue != '' && in_array($rgxp, array('date', 'time', 'datim'))) {
                 try {
                     $objDate = new \Date($varValue, \Date::getFormatFromRgxp($rgxp));
                     $varValue = $objDate->tstamp;
                 } catch (\OutOfBoundsException $e) {
                     $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $varValue));
                 }
             }
             // Make sure that unique fields are unique (check the eval setting first -> #3063)
             if ($arrData['eval']['unique'] && $varValue != '' && !$this->Database->isUniqueValue('tl_member', $field, $varValue, $this->User->id)) {
                 $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrData['label'][0] ?: $field));
             }
             // Trigger the save_callback (see #5247)
             if ($objWidget->submitInput() && !$objWidget->hasErrors() && is_array($arrData['save_callback'])) {
                 foreach ($arrData['save_callback'] as $callback) {
                     try {
                         if (is_array($callback)) {
                             $this->import($callback[0]);
                             $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this->User, $this);
                         } elseif (is_callable($callback)) {
                             $varValue = $callback($varValue, $this->User, $this);
                         }
                     } catch (\Exception $e) {
                         $objWidget->class = 'error';
                         $objWidget->addError($e->getMessage());
                     }
                 }
             }
             // Do not submit the field if there are errors
             if ($objWidget->hasErrors()) {
                 $doNotSubmit = true;
             } elseif ($objWidget->submitInput()) {
                 // Store the form data
                 $_SESSION['FORM_DATA'][$field] = $varValue;
                 // Set the correct empty value (see #6284, #6373)
                 if ($varValue === '') {
                     $varValue = $objWidget->getEmptyValue();
                 }
                 // Encrypt the value (see #7815)
                 if ($arrData['eval']['encrypt']) {
                     $varValue = \Encryption::encrypt($varValue);
                 }
                 // Set the new value
                 if ($varValue !== $this->User->{$field}) {
                     $this->User->{$field} = $varValue;
                     // Set the new field in the member model
                     $blnModified = true;
                     $objMember->{$field} = $varValue;
                 }
             }
         }
         if ($objWidget instanceof \uploadable) {
             $hasUpload = true;
         }
         $temp = $objWidget->parse();
         $this->Template->fields .= $temp;
         $arrFields[$strGroup][$field] .= $temp;
         ++$row;
     }
     // Save the model
     if ($blnModified) {
         $objMember->tstamp = time();
         $objMember->save();
         // Create a new version
         if ($GLOBALS['TL_DCA'][$strTable]['config']['enableVersioning']) {
             $objVersions->create();
             $this->log('A new version of record "' . $strTable . '.id=' . $objMember->id . '" has been created' . $this->getParentEntries($strTable, $objMember->id), __METHOD__, TL_GENERAL);
         }
     }
     $this->Template->hasError = $doNotSubmit;
     // Redirect or reload if there was no error
     if (\Input::post('FORM_SUBMIT') == 'tl_member_' . $this->id && !$doNotSubmit) {
         // HOOK: updated personal data
         if (isset($GLOBALS['TL_HOOKS']['updatePersonalData']) && is_array($GLOBALS['TL_HOOKS']['updatePersonalData'])) {
             foreach ($GLOBALS['TL_HOOKS']['updatePersonalData'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($this->User, $_SESSION['FORM_DATA'], $this);
             }
         }
         // Call the onsubmit_callback
         if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'])) {
             foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'] as $callback) {
                 if (is_array($callback)) {
                     $this->import($callback[0]);
                     $this->{$callback[0]}->{$callback[1]}($this->User, $this);
                 } elseif (is_callable($callback)) {
                     $callback($this->User, $this);
                 }
             }
         }
         // Check whether there is a jumpTo page
         if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
             $this->jumpToOrReload($objJumpTo->row());
         }
         \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['savedData']);
         $this->reload();
     }
     $this->Template->loginDetails = $GLOBALS['TL_LANG']['tl_member']['loginDetails'];
     $this->Template->addressDetails = $GLOBALS['TL_LANG']['tl_member']['addressDetails'];
     $this->Template->contactDetails = $GLOBALS['TL_LANG']['tl_member']['contactDetails'];
     $this->Template->personalData = $GLOBALS['TL_LANG']['tl_member']['personalData'];
     // Add the groups
     foreach ($arrFields as $k => $v) {
         $this->Template->{$k} = $v;
         // backwards compatibility
         $key = $k . ($k == 'personal' ? 'Data' : 'Details');
         $arrGroups[$GLOBALS['TL_LANG']['tl_member'][$key]] = $v;
     }
     $this->Template->categories = $arrGroups;
     $this->Template->formId = 'tl_member_' . $this->id;
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['saveData']);
     $this->Template->action = \Environment::get('indexFreeRequest');
     $this->Template->enctype = $hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded';
     $this->Template->rowLast = 'row_' . $row . ($row % 2 == 0 ? ' even' : ' odd');
     $this->Template->message = \Message::generate(false, true);
 }
Exemplo n.º 21
0
        $file = 'cache/blog_' . $_FILES['import_file']['name'];
        $imported = 0;
        try {
            $posts = new SimpleXMLElement(file_get_contents($file));
            foreach ($posts->channel->item as $entry) {
                $dc = $entry->children('http://purl.org/dc/elements/1.1/');
                $content = $entry->children('http://purl.org/rss/1.0/modules/content/');
                $post = array('title' => (string) $entry->title, 'author' => (string) $dc->creator, 'ts' => gmdate('Y-m-d H:i:s', strtotime($entry->pubDate)), 'published' => $_POST['published'], 'body' => str_replace("\n", "<br />\n", (string) $content->encoded), 'tags' => '');
                $sep = '';
                for ($i = 0; $i < count($entry->category); $i++) {
                    $post['tags'] .= $sep . $entry->category[$i]->attributes()->nicename;
                    $sep = ', ';
                }
                $p = new blog\Post($post);
                if ($p->put()) {
                    Versions::add($p);
                    $imported++;
                }
            }
            echo '<p>' . i18n_getf('Imported %d posts.', $imported) . '</p>';
            echo '<p><a href="/blog/admin">' . i18n_get('Continue') . '</a></p>';
        } catch (Exception $e) {
            echo '<p><strong>' . i18n_get('Error importing file') . ': ' . $e->getMessage() . '</strong></p>';
            echo '<p><a href="/blog/admin">' . i18n_get('Back') . '</a></p>';
        }
        return;
    } else {
        echo '<p><strong>' . i18n_get('Error uploading file.') . '</strong></p>';
    }
}
$o = new StdClass();
Exemplo n.º 22
0
 /**
  * @depends test_get_classes
  */
 function test_recent_user()
 {
     // recent with user
     DB::execute('update versions set user = 1');
     $recent = Versions::recent(1);
     $this->assertEquals(count($recent), 2);
 }
Exemplo n.º 23
0
 /**
  * Generate the module
  */
 protected function compile()
 {
     /** @var \PageModel $objPage */
     global $objPage;
     $this->import('FrontendUser', 'User');
     $GLOBALS['TL_LANGUAGE'] = $objPage->language;
     \System::loadLanguageFile('tl_member');
     $this->loadDataContainer('tl_member');
     // Old password widget
     $arrFields['oldPassword'] = array('name' => 'oldpassword', 'label' => &$GLOBALS['TL_LANG']['MSC']['oldPassword'], 'inputType' => 'text', 'eval' => array('mandatory' => true, 'preserveTags' => true, 'hideInput' => true));
     // New password widget
     $arrFields['newPassword'] = $GLOBALS['TL_DCA']['tl_member']['fields']['password'];
     $arrFields['newPassword']['name'] = 'password';
     $arrFields['newPassword']['label'] =& $GLOBALS['TL_LANG']['MSC']['newPassword'];
     $row = 0;
     $strFields = '';
     $doNotSubmit = false;
     $objMember = \MemberModel::findByPk($this->User->id);
     $strTable = $objMember->getTable();
     // Initialize the versioning (see #8301)
     $objVersions = new \Versions($strTable, $objMember->id);
     $objVersions->setUsername($objMember->username);
     $objVersions->setUserId(0);
     $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1');
     $objVersions->initialize();
     /** @var \FormTextField $objOldPassword */
     $objOldPassword = null;
     /** @var \FormPassword $objNewPassword */
     $objNewPassword = null;
     // Initialize the widgets
     foreach ($arrFields as $strKey => $arrField) {
         /** @var \Widget $strClass */
         $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']];
         // Continue if the class is not defined
         if (!class_exists($strClass)) {
             continue;
         }
         $arrField['eval']['tableless'] = $this->tableless;
         $arrField['eval']['required'] = $arrField['eval']['mandatory'];
         /** @var \Widget $objWidget */
         $objWidget = new $strClass($strClass::getAttributesFromDca($arrField, $arrField['name']));
         $objWidget->storeValues = true;
         $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd');
         // Increase the row count if it is a password field
         if ($objWidget instanceof \FormPassword) {
             $objWidget->rowClassConfirm = 'row_' . ++$row . ($row % 2 == 0 ? ' even' : ' odd');
         }
         ++$row;
         // Store the widget objects
         $strVar = 'obj' . ucfirst($strKey);
         ${$strVar} = $objWidget;
         // Validate the widget
         if (\Input::post('FORM_SUBMIT') == 'tl_change_password') {
             $objWidget->validate();
             // Validate the old password
             if ($strKey == 'oldPassword') {
                 if (\Encryption::test($objMember->password)) {
                     $blnAuthenticated = \Encryption::verify($objWidget->value, $objMember->password);
                 } else {
                     list($strPassword, $strSalt) = explode(':', $objMember->password);
                     $blnAuthenticated = $strSalt == '' ? $strPassword === sha1($objWidget->value) : $strPassword === sha1($strSalt . $objWidget->value);
                 }
                 if (!$blnAuthenticated) {
                     $objWidget->value = '';
                     $objWidget->addError($GLOBALS['TL_LANG']['MSC']['oldPasswordWrong']);
                     sleep(2);
                     // Wait 2 seconds while brute forcing :)
                 }
             }
             if ($objWidget->hasErrors()) {
                 $doNotSubmit = true;
             }
         }
         $strFields .= $objWidget->parse();
     }
     $this->Template->fields = $strFields;
     $this->Template->hasError = $doNotSubmit;
     // Store the new password
     if (\Input::post('FORM_SUBMIT') == 'tl_change_password' && !$doNotSubmit) {
         $objMember->tstamp = time();
         $objMember->password = $objNewPassword->value;
         $objMember->save();
         // Create a new version
         if ($GLOBALS['TL_DCA'][$strTable]['config']['enableVersioning']) {
             $objVersions->create();
         }
         // HOOK: set new password callback
         if (isset($GLOBALS['TL_HOOKS']['setNewPassword']) && is_array($GLOBALS['TL_HOOKS']['setNewPassword'])) {
             foreach ($GLOBALS['TL_HOOKS']['setNewPassword'] as $callback) {
                 $this->import($callback[0]);
                 $this->{$callback[0]}->{$callback[1]}($objMember, $objNewPassword->value, $this);
             }
         }
         // Check whether there is a jumpTo page
         if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
             $this->jumpToOrReload($objJumpTo->row());
         }
         \Message::addConfirmation($GLOBALS['TL_LANG']['MSC']['newPasswordSet']);
         $this->reload();
     }
     $this->Template->action = \Environment::get('indexFreeRequest');
     $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['changePassword']);
     $this->Template->rowLast = 'row_' . $row . ' row_last' . ($row % 2 == 0 ? ' even' : ' odd');
     $this->Template->tableless = $this->tableless;
     $this->Template->message = \Message::generate(false, true);
 }
Exemplo n.º 24
0
    /**
     * Auto-generate a form to override all records that are currently shown
     *
     * @return string
     */
    public function overrideAll()
    {
        if ($GLOBALS['TL_DCA'][$this->strTable]['config']['notEditable']) {
            $this->log('Table "' . $this->strTable . '" is not editable', __METHOD__, TL_ERROR);
            $this->redirect('contao/main.php?act=error');
        }
        $return = '';
        $this->import('BackendUser', 'User');
        // Get current IDs from session
        $session = $this->Session->getData();
        $ids = $session['CURRENT']['IDS'];
        // Save field selection in session
        if (\Input::post('FORM_SUBMIT') == $this->strTable . '_all' && \Input::get('fields')) {
            $session['CURRENT'][$this->strTable] = \Input::post('all_fields');
            $this->Session->setData($session);
        }
        // Add fields
        $fields = $session['CURRENT'][$this->strTable];
        if (!empty($fields) && is_array($fields) && \Input::get('fields')) {
            $class = 'tl_tbox';
            $formFields = array();
            // Save record
            if (\Input::post('FORM_SUBMIT') == $this->strTable) {
                foreach ($ids as $id) {
                    $this->intId = $id;
                    $this->procedure = array('id=?');
                    $this->values = array($this->intId);
                    $this->blnCreateNewVersion = false;
                    // Get the field values
                    $objRow = $this->Database->prepare("SELECT * FROM " . $this->strTable . " WHERE id=?")->limit(1)->execute($this->intId);
                    // Store the active record
                    $this->objActiveRecord = $objRow;
                    $objVersions = new \Versions($this->strTable, $this->intId);
                    $objVersions->initialize();
                    // Store all fields
                    foreach ($fields as $v) {
                        // Check whether field is excluded
                        if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['exclude']) {
                            continue;
                        }
                        $this->strField = $v;
                        $this->strInputName = $v;
                        $this->varValue = '';
                        // Make sure the new value is applied
                        $GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['eval']['alwaysSave'] = true;
                        // Store value
                        $this->row();
                    }
                    // Post processing
                    if (!$this->noReload) {
                        // Call the onsubmit_callback
                        if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) {
                            foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) {
                                if (is_array($callback)) {
                                    $this->import($callback[0]);
                                    $this->{$callback[0]}->{$callback[1]}($this);
                                } elseif (is_callable($callback)) {
                                    $callback($this);
                                }
                            }
                        }
                        // Create a new version
                        if ($this->blnCreateNewVersion) {
                            $objVersions->create();
                            // Call the onversion_callback
                            if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'])) {
                                @trigger_error('Using the onversion_callback has been deprecated and will no longer work in Contao 5.0. Use the oncreate_version_callback instead.', E_USER_DEPRECATED);
                                foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onversion_callback'] as $callback) {
                                    if (is_array($callback)) {
                                        $this->import($callback[0]);
                                        $this->{$callback[0]}->{$callback[1]}($this->strTable, $this->intId, $this);
                                    } elseif (is_callable($callback)) {
                                        $callback($this->strTable, $this->intId, $this);
                                    }
                                }
                            }
                        }
                        // Set the current timestamp (-> DO NOT CHANGE ORDER version - timestamp)
                        if ($GLOBALS['TL_DCA'][$this->strTable]['config']['dynamicPtable']) {
                            $this->Database->prepare("UPDATE " . $this->strTable . " SET ptable=?, tstamp=? WHERE id=?")->execute($this->ptable, time(), $this->intId);
                        } else {
                            $this->Database->prepare("UPDATE " . $this->strTable . " SET tstamp=? WHERE id=?")->execute(time(), $this->intId);
                        }
                    }
                }
            }
            $blnIsFirst = true;
            // Begin current row
            $return .= '
<div class="' . $class . '">';
            foreach ($fields as $v) {
                // Check whether field is excluded
                if ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$v]['exclude']) {
                    continue;
                }
                $formFields[] = $v;
                $this->intId = 0;
                $this->procedure = array('id=?');
                $this->values = array($this->intId);
                $this->strField = $v;
                $this->strInputName = $v;
                $this->varValue = '';
                // Autofocus the first field
                if ($blnIsFirst && $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'text') {
                    $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['autofocus'] = 'autofocus';
                    $blnIsFirst = false;
                }
                // Disable auto-submit
                $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['eval']['submitOnChange'] = false;
                $return .= $this->row();
            }
            // Close box
            $return .= '
<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars(implode(',', $formFields)) . '">
</div>';
            // Submit buttons
            $arrButtons = array();
            $arrButtons['save'] = '<input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['save']) . '">';
            $arrButtons['saveNclose'] = '<input type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['saveNclose']) . '">';
            // Call the buttons_callback (see #4691)
            if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) {
                foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) {
                    if (is_array($callback)) {
                        $this->import($callback[0]);
                        $arrButtons = $this->{$callback[0]}->{$callback[1]}($arrButtons, $this);
                    } elseif (is_callable($callback)) {
                        $arrButtons = $callback($arrButtons, $this);
                    }
                }
            }
            // Add the form
            $return = '

<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($this->noReload ? '

<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return . '

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  ' . implode(' ', $arrButtons) . '
</div>

</div>
</form>';
            // Set the focus if there is an error
            if ($this->noReload) {
                $return .= '

<script>
  window.addEvent(\'domready\', function() {
    Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20));
  });
</script>';
            }
            // Reload the page to prevent _POST variables from being sent twice
            if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) {
                if (\Input::post('saveNclose')) {
                    \System::setCookie('BE_PAGE_OFFSET', 0, 0);
                    $this->redirect($this->getReferer());
                }
                $this->reload();
            }
        } else {
            $options = '';
            $fields = array();
            // Add fields of the current table
            $fields = array_merge($fields, array_keys($GLOBALS['TL_DCA'][$this->strTable]['fields']));
            // Add meta fields if the current user is an administrator
            if ($this->User->isAdmin) {
                if ($this->Database->fieldExists('sorting', $this->strTable) && !in_array('sorting', $fields)) {
                    array_unshift($fields, 'sorting');
                }
                if ($this->Database->fieldExists('pid', $this->strTable) && !in_array('pid', $fields)) {
                    array_unshift($fields, 'pid');
                }
            }
            // Show all non-excluded fields
            foreach ($fields as $field) {
                if ($field == 'pid' || $field == 'sorting' || !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['exclude'] && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['eval']['doNotShow'] && (strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['inputType']) || is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['input_field_callback']))) {
                    $options .= '
  <input type="checkbox" name="all_fields[]" id="all_' . $field . '" class="tl_checkbox" value="' . specialchars($field) . '"> <label for="all_' . $field . '" class="tl_checkbox_label">' . ($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['label'][0] ?: $GLOBALS['TL_LANG']['MSC'][$field][0]) . '</label><br>';
                }
            }
            $blnIsError = $_POST && empty($_POST['all_fields']);
            // Return the select menu
            $return .= '

<form action="' . ampersand(\Environment::get('request'), true) . '&amp;fields=1" id="' . $this->strTable . '_all" class="tl_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '_all">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($blnIsError ? '

<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . '

<div class="tl_tbox">
<fieldset class="tl_checkbox_container">
  <legend' . ($blnIsError ? ' class="error"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['all_fields'][0] . '</legend>
  <input type="checkbox" id="check_all" class="tl_checkbox" onclick="Backend.toggleCheckboxes(this)"> <label for="check_all" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>' . $options . '
</fieldset>' . ($blnIsError ? '
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['all_fields'] . '</p>' : (\Config::get('showHelp') && strlen($GLOBALS['TL_LANG']['MSC']['all_fields'][1]) ? '
<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['all_fields'][1] . '</p>' : '')) . '
</div>

</div>

<div class="tl_formbody_submit">

<div class="tl_submit_container">
  <input type="submit" name="save" id="save" class="tl_submit" accesskey="s" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['continue']) . '">
</div>

</div>
</form>';
        }
        // Return
        return '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>' . $return;
    }
 /**
  * Toggle the visibility state.
  *
  * @param int  $recordId Record id.
  * @param bool $newState New state.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 private function toggleVisibility($recordId, $newState)
 {
     if (!$this->hasAccess()) {
         $this->log(sprintf('Not enough permission to show/shide record ID "%s"', $recordId), __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $versions = new \Versions($this->table, $recordId);
     if (isset($GLOBALS['TL_DCA'][$this->table]['fields'][$this->column]['save_callback'])) {
         foreach ((array) $GLOBALS['TL_DCA'][$this->table]['fields'][$this->column]['save_callback'] as $callback) {
             $instance = new $callback[0]();
             $instance->{$callback}[1]($newState, $this);
         }
     }
     $this->database->prepare(sprintf('UPDATE %s %s WHERE id=?', $this->table, '%s'))->set(array('tstamp' => time(), $this->column => $newState ? '1' : ''))->execute($recordId);
     $versions->create();
 }
Exemplo n.º 26
0
 /**
  * Disable/enable a user group
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  *
  * @throws Contao\CoreBundle\Exception\AccessDeniedException
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     $this->checkPermission();
     // Check the field access
     if (!$this->User->hasAccess('tl_faq::published', 'alexf')) {
         throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to publish/unpublish FAQ ID ' . $intId . '.');
     }
     $objVersions = new Versions('tl_faq', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_faq']['fields']['published']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_faq']['fields']['published']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_faq SET tstamp=" . time() . ", published='" . ($blnVisible ? '1' : '') . "' WHERE id=?")->execute($intId);
     $objVersions->create();
 }
Exemplo n.º 27
0
    $res->error = __('Authorization required.');
    echo json_encode($res);
    return;
}
$error = false;
$o = new Block($_GET['id']);
if ($o->error) {
    $error = $o->error;
} else {
    foreach ($_POST as $k => $v) {
        if ($k != $o->key && isset($o->data[$k])) {
            $o->{$k} = $v;
        }
    }
    if (!$o->put()) {
        $error = $o->error;
    } else {
        Versions::add($o);
        $_POST['id'] = $_GET['id'];
        $this->hook('blocks/edit', $_POST);
    }
}
$res = new StdClass();
if ($error) {
    $res->success = false;
    $res->error = $error;
} else {
    $res->success = true;
    $res->data = $_GET['id'];
}
echo json_encode($res);
Exemplo n.º 28
0
 /**
  * Toggle the visibility of an element
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Check permissions to edit
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     // The onload_callbacks vary depending on the dynamic parent table (see #4894)
     if (is_array($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_content']['config']['onload_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $this->{$callback}[0]->{$callback}[1]($dc ?: $this);
             } elseif (is_callable($callback)) {
                 $callback($dc ?: $this);
             }
         }
     }
     // Check permissions to publish
     if (!$this->User->hasAccess('tl_content::invisible', 'alexf')) {
         $this->log('Not enough permissions to show/hide content element ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_content', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_content']['fields']['invisible']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback}[0]->{$callback}[1]($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_content SET tstamp=" . time() . ", invisible='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_content.id=' . $intId . '" has been created' . $this->getParentEntries('tl_content', $intId), __METHOD__, TL_GENERAL);
 }
Exemplo n.º 29
0
 /**
  * Disable/enable a user group
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     $this->checkPermission();
     // Protect own account
     if ($this->User->id == $intId) {
         return;
     }
     // Check the field access
     if (!$this->User->hasAccess('tl_user::disable', 'alexf')) {
         $this->log('Not enough permissions to activate/deactivate user ID "' . $intId . '"', __METHOD__, TL_ERROR);
         $this->redirect('contao/main.php?act=error');
     }
     $objVersions = new Versions('tl_user', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_user']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_user']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_user SET tstamp=" . time() . ", disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     // Remove the session if the user is disabled (see #5353)
     if (!$blnVisible) {
         $this->Database->prepare("DELETE FROM tl_session WHERE name='BE_USER_AUTH' AND pid=?")->execute($intId);
     }
 }
Exemplo n.º 30
0
 /**
  * Disable/enable a user group
  *
  * @param integer       $intId
  * @param boolean       $blnVisible
  * @param DataContainer $dc
  *
  * @throws Contao\CoreBundle\Exception\AccessDeniedException
  */
 public function toggleVisibility($intId, $blnVisible, DataContainer $dc = null)
 {
     // Set the ID and action
     Input::setGet('id', $intId);
     Input::setGet('act', 'toggle');
     if ($dc) {
         $dc->id = $intId;
         // see #8043
     }
     // Check the field access
     if (!$this->User->hasAccess('tl_member_group::disable', 'alexf')) {
         throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to activate/deactivate member group ID ' . $intId . '.');
     }
     $objVersions = new Versions('tl_member_group', $intId);
     $objVersions->initialize();
     // Trigger the save_callback
     if (is_array($GLOBALS['TL_DCA']['tl_member_group']['fields']['disable']['save_callback'])) {
         foreach ($GLOBALS['TL_DCA']['tl_member_group']['fields']['disable']['save_callback'] as $callback) {
             if (is_array($callback)) {
                 $this->import($callback[0]);
                 $blnVisible = $this->{$callback[0]}->{$callback[1]}($blnVisible, $dc ?: $this);
             } elseif (is_callable($callback)) {
                 $blnVisible = $callback($blnVisible, $dc ?: $this);
             }
         }
     }
     // Update the database
     $this->Database->prepare("UPDATE tl_member_group SET tstamp=" . time() . ", disable='" . ($blnVisible ? '' : 1) . "' WHERE id=?")->execute($intId);
     $objVersions->create();
     $this->log('A new version of record "tl_member_group.id=' . $intId . '" has been created' . $this->getParentEntries('tl_member_group', $intId), __METHOD__, TL_GENERAL);
 }