2016-10-06 15:57:01 +00:00
|
|
|
<?php
|
2018-12-10 12:13:27 +00:00
|
|
|
|
2016-10-06 15:57:01 +00:00
|
|
|
/**
|
|
|
|
* Project:
|
|
|
|
* Contenido Content Management System
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Requirements:
|
|
|
|
* @con_php_req 5.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @package Contenido Backend classes
|
|
|
|
* @version 1.1
|
|
|
|
* @author Unknown
|
|
|
|
* @copyright four for business AG <www.4fb.de>
|
|
|
|
* @license http://www.contenido.org/license/LIZENZ.txt
|
|
|
|
* @link http://www.4fb.de
|
|
|
|
* @link http://www.contenido.org
|
|
|
|
*
|
|
|
|
* {@internal
|
|
|
|
* created unknown
|
|
|
|
* modified 2011-03-15, Murat Purc, adapted to new GenericDB, partly ported to PHP 5, formatting
|
|
|
|
*
|
2019-07-03 11:58:28 +00:00
|
|
|
* $Id$:
|
2016-10-06 15:57:01 +00:00
|
|
|
* }}
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (!defined('CON_FRAMEWORK')) {
|
|
|
|
die('Illegal call');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define("QUESTIONACTION_PROMPT", "prompt");
|
2018-12-10 12:13:27 +00:00
|
|
|
define("QUESTIONACTION_YESNO", "yesno");
|
2016-10-06 15:57:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* class cApiClickableAction
|
|
|
|
* cApiClickableAction is a subclass of cApiAction. It provides an image for visual
|
|
|
|
* representation. Inherited classes should call the "setNamedAction" operation in
|
|
|
|
* their constructors; on-the-fly-implementations should call it directly after
|
|
|
|
* creating an object instance.
|
|
|
|
*/
|
2018-12-10 12:13:27 +00:00
|
|
|
class cApiClickableAction extends cApiAction {
|
|
|
|
/* * * Attributes: ** */
|
2016-10-06 15:57:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Help text
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $_helpText;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cHTMLLink for rendering the icon
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $_link;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cHTMLImage for rendering the icon
|
|
|
|
* @access private
|
|
|
|
*/
|
|
|
|
private $_img;
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function __construct() {
|
2016-10-06 15:57:01 +00:00
|
|
|
global $area;
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
$this->_area = $area;
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_frame = 4;
|
|
|
|
$this->_target = "right_bottom";
|
|
|
|
|
|
|
|
$this->_link = new cHTMLLink;
|
2018-12-10 12:13:27 +00:00
|
|
|
$this->_img = new cHTMLImage;
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_img->setBorder(0);
|
|
|
|
$this->_img->setStyle("padding-left: 1px; padding-right: 1px;");
|
|
|
|
|
|
|
|
$this->_parameters = array();
|
|
|
|
|
|
|
|
$this->setEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the action icon for this action.
|
|
|
|
*
|
|
|
|
* @param string icon Path to the icon. Relative to the backend, if not passed as absolute path.
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setIcon($icon) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_img->setSrc($icon);
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function getIcon() {
|
2016-10-06 15:57:01 +00:00
|
|
|
return $this->_img;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets this class to use a specific action, example "con_makestart".
|
|
|
|
*
|
|
|
|
* @param string actionName Name of the action to use. This action must exist in the actions table before
|
|
|
|
* using it, otherwise, this method will fail.
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setNamedAction($actionName) {
|
|
|
|
if ($this->loadBy("name", $actionName) !== false) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$a = new cApiArea;
|
|
|
|
$a->loadByPrimaryKey($this->get("idarea"));
|
|
|
|
|
|
|
|
$this->_namedAction = $actionName;
|
|
|
|
$this->_area = $a->get("name");
|
|
|
|
|
|
|
|
$this->_parameters = array();
|
|
|
|
$this->_wantParameters = array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setDisabled() {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_enabled = false;
|
|
|
|
$this->_onDisable();
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setEnabled() {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_enabled = true;
|
|
|
|
$this->_onEnable();
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
protected function _onDisable() {
|
|
|
|
|
2016-10-06 15:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
protected function _onEnable() {
|
|
|
|
|
2016-10-06 15:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change linked area
|
|
|
|
*/
|
2018-12-10 12:13:27 +00:00
|
|
|
public function changeArea($sArea) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_area = $sArea;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function wantParameter($parameter) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_wantParameters[] = $parameter;
|
|
|
|
|
|
|
|
$this->_wantParameters = array_unique($this->_wantParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sets the help text for this action.
|
|
|
|
*
|
|
|
|
* @param string helptext The helptext to apply
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setHelpText($helptext) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_helpText = $helptext;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function getHelpText() {
|
2016-10-06 15:57:01 +00:00
|
|
|
return $this->_helpText;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setParameter($name, $value) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_parameters[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function process($parameters) {
|
2016-10-06 15:57:01 +00:00
|
|
|
echo "Process should be overridden";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function render() {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_img->setAlt($this->_helpText);
|
|
|
|
|
|
|
|
foreach ($this->_parameters as $name => $value) {
|
|
|
|
$this->_link->setCustom($name, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_link->setAlt($this->_helpText);
|
|
|
|
$this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
|
|
|
|
$this->_link->setTargetFrame($this->_target);
|
|
|
|
$this->_link->setContent($this->_img);
|
|
|
|
|
|
|
|
if ($this->_enabled == true) {
|
|
|
|
return ($this->_link->render());
|
|
|
|
} else {
|
|
|
|
return ($this->_img->render());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderText() {
|
|
|
|
foreach ($this->_parameters as $name => $value) {
|
|
|
|
$this->_link->setCustom($name, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_link->setAlt($this->_helpText);
|
|
|
|
$this->_link->setCLink($this->_area, $this->_frame, $this->_namedAction);
|
|
|
|
$this->_link->setTargetFrame($this->_target);
|
|
|
|
$this->_link->setContent($this->_helpText);
|
|
|
|
|
|
|
|
if ($this->_enabled == true) {
|
|
|
|
return ($this->_link->render());
|
|
|
|
} else {
|
|
|
|
return ($this->_helpText);
|
|
|
|
}
|
|
|
|
}
|
2018-12-10 12:13:27 +00:00
|
|
|
|
2016-10-06 15:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
class cApiClickableQuestionAction extends cApiClickableAction {
|
2016-10-06 15:57:01 +00:00
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function __construct() {
|
2016-10-06 15:57:01 +00:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setQuestionMode($mode) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_mode = $mode;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setQuestion($question) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_question = $question;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function setResultVar($var) {
|
2016-10-06 15:57:01 +00:00
|
|
|
$this->_resultVar = $var;
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
public function render() {
|
|
|
|
switch ($this->_mode) {
|
2016-10-06 15:57:01 +00:00
|
|
|
case QUESTIONACTION_PROMPT:
|
2018-12-10 12:13:27 +00:00
|
|
|
$this->_link->attachEventDefinition("_" . get_class($this) . rand(), "onclick", 'var answer = prompt("' . clHtmlSpecialChars($this->_question) . '");if (answer == null) {return false;} else { this.href = this.href + "&' . $this->_resultVar . '="+answer; return true;}');
|
2016-10-06 15:57:01 +00:00
|
|
|
break;
|
|
|
|
case QUESTIONACTION_YESNO:
|
|
|
|
default:
|
2018-12-10 12:13:27 +00:00
|
|
|
$this->_link->attachEventDefinition("_" . get_class($this) . rand(), "onclick", 'var answer = confirm("' . clHtmlSpecialChars($this->_question) . '");if (answer == false) {return false;} else { return true;}');
|
|
|
|
break;
|
2016-10-06 15:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::render();
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:13:27 +00:00
|
|
|
}
|