import('BackendUser', 'User');
}
public function addProjects($arrRow)
{
return '
'.$arrRow['title'].'
' . "\n";
}
/**
* Return the file picker wizard
* @param \DataContainer
* @return string
*/
public function filePicker(\DataContainer $dc)
{
return ' ' . \Image::getHtml('pickfile.gif', $GLOBALS['TL_LANG']['MSC']['filepicker'], 'style="vertical-align:top;cursor:pointer"') . '';
}
/**
* Return the link picker wizard
* @param \DataContainer
* @return string
*/
public function pagePicker(\DataContainer $dc)
{
return ' field . '\',\'tag\':\'ctrl_'. $dc->field . ((\Input::get('act') == 'editAll') ? '_' . $dc->id : '') . '\',\'self\':this});return false">' . \Image::getHtml('pickpage.gif', $GLOBALS['TL_LANG']['MSC']['pagepicker'], 'style="vertical-align:top;cursor:pointer"') . '';
}
/**
* Return the "toggle visibility" button
* @param array
* @param string
* @param string
* @param string
* @param string
* @param string
* @return string
*/
public function toggleIcon($row, $href, $label, $title, $icon, $attributes)
{
if (strlen(\Input::get('tid')))
{
$this->toggleVisibility(\Input::get('tid'), (\Input::get('state') == 1));
$this->redirect($this->getReferer());
}
// Check permissions AFTER checking the tid, so hacking attempts are logged
if (!$this->User->hasAccess('tl_esm_clients_projects::invisible', 'alexf'))
{
return '';
}
$href .= '&id='.\Input::get('id').'&tid='.$row['id'].'&state='.$row['invisible'];
if ($row['invisible'])
{
$icon = 'invisible.gif';
}
return ''.\Image::getHtml($icon, $label).' ';
}
/**
* Toggle the visibility of an element
* @param integer
* @param boolean
*/
public function toggleVisibility($intId, $blnVisible)
{
// 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_esm_clients_projects']['config']['onload_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_esm_clients_projects']['config']['onload_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$this->$callback[0]->$callback[1]($this);
}
elseif (is_callable($callback))
{
$callback($this);
}
}
}
// Check permissions to publish
if (!$this->User->hasAccess('tl_esm_clients_projects::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_esm_clients_projects', $intId);
$objVersions->initialize();
// Trigger the save_callback
if (is_array($GLOBALS['TL_DCA']['tl_esm_clients_projects']['fields']['invisible']['save_callback']))
{
foreach ($GLOBALS['TL_DCA']['tl_esm_clients_projects']['fields']['invisible']['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_esm_clients_projects SET tstamp=". time() .", invisible='" . ($blnVisible ? '' : 1) . "' WHERE id=?")
->execute($intId);
$objVersions->create();
$this->log('A new version of record "tl_esm_clients_projects.id='.$intId.'" has been created', __METHOD__, TL_GENERAL);
}
public function getTypes(\DataContainer $dc)
{
$arrOptions = array();
$Types = \EsmClientsSettingsModel::findByType('type');
if (!is_null($Types))
{
while($Types->next())
{
$arrOptions[$Types->id] = $Types->title;
}
}
return $arrOptions;
}
public function getServices(\DataContainer $dc)
{
$arrOptions = array();
$Services = \EsmClientsSettingsModel::findByType('services');
if (!is_null($Services))
{
while($Services->next())
{
$arrOptions[$Services->id] = $Services->title;
}
}
return $arrOptions;
}
public function getTech(\DataContainer $dc)
{
$arrOptions = array();
$Tech = \EsmClientsSettingsModel::findByType('tech');
if (!is_null($Tech))
{
while($Tech->next())
{
$arrOptions[$Tech->id] = $Tech->title;
}
}
return $arrOptions;
}
/**
* Auto-generate alias if it has not been set yet
* @param $varValue
* @param \DataContainer $dc
* @return string
* @throws \Exception
* @internal param $mixed
* @internal param $ \DataContainer
*/
public function generateAlias($varValue, \DataContainer $dc)
{
$autoAlias = false;
// Generate alias if there is none
if ($varValue == '')
{
$autoAlias = true;
$objParent = EsmClientsModel::findByPk($dc->activeRecord->pid);
$varValue = standardize(\String::restoreBasicEntities($dc->activeRecord->title).(($objParent !== null) ? '__'.($objParent->alias != '' ? $objParent->alias : \String::restoreBasicEntities($objParent->title)) : ''));
}
$objAlias = $this->Database->prepare("SELECT id FROM tl_esm_clients_projects WHERE alias=?")
->execute($varValue);
// Check whether the alias exists
if ($objAlias->numRows > 1 && !$autoAlias)
{
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
}
// Add ID to alias
if ($objAlias->numRows && $autoAlias)
{
$varValue .= '-' . $dc->id;
}
return $varValue;
}
/**
* Automatically generate the folder URL aliases
* @param array
* @param \DataContainer
* @return array
*/
public function addAliasButton($arrButtons, \DataContainer $dc)
{
// Generate the aliases
if (\Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias']))
{
$session = $this->Session->getData();
$ids = $session['CURRENT']['IDS'];
foreach ($ids as $id)
{
$objProjects = EsmClientsProjectsModel::findByPk($id);
if ($objProjects === null)
{
continue;
}
$dc->id = $id;
$dc->activeRecord = $objProjects;
$strAlias = '';
// Generate new alias through save callbacks
foreach ($GLOBALS['TL_DCA'][$dc->table]['fields']['alias']['save_callback'] as $callback)
{
if (is_array($callback))
{
$this->import($callback[0]);
$strAlias = $this->$callback[0]->$callback[1]($strAlias, $dc);
}
elseif (is_callable($callback))
{
$strAlias = $callback($strAlias, $dc);
}
}
// The alias has not changed
if ($strAlias == $objProjects->alias)
{
continue;
}
// Initialize the version manager
$objVersions = new \Versions($dc->table, $id);
$objVersions->initialize();
// Store the new alias
$this->Database->prepare("UPDATE tl_esm_clients_projects SET alias=? WHERE id=?")
->execute($strAlias, $id);
// Create a new version
$objVersions->create();
}
$this->redirect($this->getReferer());
}
// Add the button
$arrButtons['alias'] = ' ';
return $arrButtons;
}
}