コード例 #1
0
	/**
	 * Implements form field for menu items selection
	 *
	 * @param  string              $name          The name of the form element
	 * @param  string              $value         The value of the element
	 * @param  SimpleXMLElement  $node          The xml element for the parameter
	 * @param  string              $control_name  The control name
	 * @return string                             The html for the element
	 */
	function _form_mos_menu_item( $name, $value, &$node, $control_name ) {
		global $_CB_database;

		$key						=	$node->attributes( 'key' );

		if ( $key ) {
			$keytype				=	$node->attributes( 'keytype' );
		} else {
			$key					=	'id';
		}

		if ( ! isset( $keytype ) ) {
			$keytype				=	'sql:int';
		}

		$title						=	$node->attributes( 'title' );
		$multi						=	( $node->attributes( 'multiple' ) == 'true' );

		if ( $this->_view ) {
			if ( $value === null ) {
				$selected			=	array();
			} else {
				if ( $multi && ( ! is_array( $value ) ) ) {
					$selected		=	explode( '|*|', $value );
				} else {
					$selected		=	array( $value );
				}
			}

			if ( count( $selected ) > 0 ) {
				foreach ( $selected as $k => $v ) {
					$selected[$k]	=	XmlTypeCleanQuote::sqlCleanQuote( $v, $keytype, $this->_pluginParams, $_CB_database );
				}

				if ( $title ) {
					$query			=	"SELECT " . $_CB_database->NameQuote( $title );
				} else {
					$query			=	"SELECT CONCAT_WS( '/', " . $_CB_database->NameQuote( 'menutype' ) . ", " . $_CB_database->NameQuote( 'title' ) . " ) AS text";
				}

				$query				.=	"\n FROM " . $_CB_database->NameQuote( '#__menu' )
									.	"\n WHERE " . $_CB_database->NameQuote( 'client_id' ) . " = 0"
									.	"\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1"
									.	"\n AND " . $_CB_database->NameQuote( 'id' ) . " > 1"
									.	"\n AND " . $_CB_database->NameQuote( $key ) . ( ( count( $selected ) == 1 ) ? ( " = " . $selected[0] ) : ( " IN (" . implode( ',', $selected ) . ")" ) )
									.	"\n ORDER BY " . $_CB_database->NameQuote( 'lft' ) . " ASC";
			} else {
				$query				=	null;
			}
		} else {
			$query					=	"SELECT " . $_CB_database->NameQuote( $key ) . " AS value";

			if ( $title ) {
				$query				.=	", " . $_CB_database->NameQuote( $title ) . " AS text";
			} else {
				$query				.=	", CONCAT_WS( '/', " . $_CB_database->NameQuote( 'menutype' ) . ", " . $_CB_database->NameQuote( 'title' ) . " ) AS text";
			}

			$query					.=	"\n FROM " . $_CB_database->NameQuote( '#__menu' )
									.	"\n WHERE " . $_CB_database->NameQuote( 'client_id' ) . " = 0"
									.	"\n AND " . $_CB_database->NameQuote( 'published' ) . " = 1"
									.	"\n AND " . $_CB_database->NameQuote( 'id' ) . " > 1"
									.	"\n ORDER BY " . $_CB_database->NameQuote( 'lft' ) . " ASC";
		}

		$defaultDefault				=	array( '', '--- ' . ( $multi ? CBTxt::T( 'Select Menu items (CTR/CMD-Click: Multiple)' ) : CBTxt::T( 'Select Menu Item' ) ) . ' ---' );

		return $this->_form_multilist_internal( $name, $value, $node, $control_name, $query, $defaultDefault, $multi );
	}
コード例 #2
0
ファイル: XmlQuery.php プロジェクト: Raul-mz/web-erpcya
 /**
  * Cleans the field value by type in a secure way for SQL
  *
  * @param  mixed  $fieldValue
  * @param  string $type         const,sql,param : string,int,float,datetime,formula
  * @return string or boolean FALSE in case of type error
  */
 public function sqlCleanQuote($fieldValue, $type)
 {
     return XmlTypeCleanQuote::sqlCleanQuote($fieldValue, $type, $this->_pluginParams, $this->_db, $this->_extDataModels);
 }
コード例 #3
0
ファイル: TableBrowser.php プロジェクト: ankaau/GathBandhan
 /**
  * Performs a table action on a click in table
  *
  * @return void
  * @throws \Exception
  */
 protected function _performTableActions()
 {
     global $_CB_framework;
     if (!isset($_REQUEST[$this->name])) {
         return;
     }
     $subtask = cbGetParam($_REQUEST[$this->name], 'subtask', '');
     if (!$subtask) {
         return;
     }
     $task_parsed = explode('/', $subtask);
     $cid = cbGetParam($_REQUEST[$this->name], 'idcid', array());
     if (!is_array($cid)) {
         $ocid = $cid;
         $cid = array();
         $cid[] = $ocid;
     }
     switch ($task_parsed[0]) {
         case 'orderup':
         case 'orderdown':
         case 'saveorder':
             if ($this->listFieldsRows) {
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                     $fieldNode = $this->listFieldsRows->getChildByNameAttr('field', 'name', $field);
                     if (!$fieldNode) {
                         $fieldNode = $this->listFieldsRows->getChildByNameAttr('param', 'name', $field);
                     }
                 } else {
                     $field = null;
                     $fieldNode = false;
                 }
                 if (!$fieldNode || $fieldNode->attributes('type') !== 'ordering' || !Access::authorised($fieldNode)) {
                     $_CB_framework->enqueueMessage(CBTxt::T('This field can not ordered'), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 if ($task_parsed[0] != 'saveorder') {
                     $dataModelValue = $cid[0];
                 } else {
                     $dataModelValue = null;
                 }
                 $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                 if (!$row) {
                     $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                     return;
                 }
                 if ($task_parsed[0] == 'saveorder') {
                     $order = cbGetParam($_REQUEST[$this->name], $field, array(0));
                 }
                 $where = '';
                 $orderinggroups = $fieldNode->getElementByPath('orderinggroups');
                 /** @var $orderinggroups SimpleXMLElement|null */
                 if ($orderinggroups) {
                     foreach ($orderinggroups->children() as $group) {
                         /** @var $group SimpleXMLElement */
                         $orderingFieldName = $group->attributes('name');
                         if ($group->getName() == 'ordering' && $orderingFieldName && array_key_exists($orderingFieldName, get_object_vars($row))) {
                             if ($task_parsed[0] != 'saveorder') {
                                 $where .= $this->_db->NameQuote($orderingFieldName) . ' = ' . XmlTypeCleanQuote::sqlCleanQuote($row->{$orderingFieldName}, $group->attributes('type'), $this->_pluginParams, $this->_db) . ' AND ';
                             } else {
                                 $where .= $orderingFieldName . "='\$row->" . $orderingFieldName . "' AND ";
                             }
                         }
                     }
                 }
                 if ($task_parsed[0] != 'saveorder') {
                     $inc = $task_parsed[0] == 'orderup' ? -1 : 1;
                     /** @var OrderedTable $row */
                     $row->move($inc, $where . $field . " > -10000 AND " . $field . " < 10000 ", $field);
                 } else {
                     $this->saveOrder($cid, $row, $order, "\$condition = \"" . $where . $field . " > -10000 AND " . $field . " < 10000 \";", $field);
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_ORDER_SUCCESS', 'Row ordered successfully!|%%COUNT%% rows ordered successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'publish':
         case 'unpublish':
         case 'enable':
         case 'disable':
         case 'setfield':
         case 'doaction':
             if ($this->listFieldsRows) {
                 $field = null;
                 switch ($task_parsed[0]) {
                     case 'publish':
                     case 'unpublish':
                         $value = $task_parsed[0] == 'publish' ? 1 : 0;
                         $field = 'published';
                         break;
                     case 'enable':
                     case 'disable':
                         $value = $task_parsed[0] == 'enable' ? 1 : 0;
                         $field = 'enabled';
                         break;
                     case 'setfield':
                         $value = $task_parsed[2];
                         break;
                     case 'doaction':
                         $value = null;
                         break;
                     default:
                         throw new \Exception(__FUNCTION__ . ': Impossible value');
                 }
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                 }
                 /** @var SimpleXMLElement $fieldNode */
                 $fieldNode = $this->listFieldsRows->xpath('(//field[@name="' . $field . '"][@onclick="toggle"])[last()]');
                 if (!$fieldNode) {
                     $fieldNode = $this->listFieldsRows->xpath('(//param[@name="' . $field . '"][@onclick="toggle"])[last()]');
                 }
                 if (!$fieldNode) {
                     // We're not a field toggle so lets check if we're a menu item for permission/usage checks:
                     $fieldNode = $this->toolbarmenu->xpath('(//menu[@name="' . $field . '"])[last()]');
                 }
                 if (!$fieldNode || !Access::authorised($fieldNode[0])) {
                     $_CB_framework->enqueueMessage(CBTxt::T('THIS_FIELD_CAN_NOT_TOGGLE_TASK', 'This field can not toggle: [task]', array('[task]' => $task_parsed[0])), 'error');
                     return;
                 }
                 $fieldNode = $fieldNode[0];
                 $taskName = CBTxt::T($fieldNode->attributes('label'));
                 if ($task_parsed[0] == 'setfield') {
                     // Check field value if allowed:
                     $this->registryEditVew->resolveXmlParamType($fieldNode);
                     if ($fieldNode->getChildByNameAttributes('option')) {
                         $valueNode = $fieldNode->getAnyChildByNameAttr('option', 'index', $value);
                         if (!$valueNode) {
                             $valueNode = $fieldNode->getAnyChildByNameAttr('option', 'value', $value);
                         }
                         if ($valueNode) {
                             $valueLabel = CBTxt::T($valueNode->data());
                             if ($valueLabel) {
                                 $taskName = $valueLabel;
                             }
                         } else {
                             $_CB_framework->enqueueMessage(CBTxt::T('This field can not be set to that value'), 'error');
                             return;
                         }
                     }
                 }
                 if (!$taskName) {
                     $taskName = $task_parsed[0];
                 }
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => strtolower($taskName))), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $c) {
                     $dataModelValue = $c;
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($task_parsed[0] == 'doaction') {
                         $this->registryEditVew->pushModelOfData($row);
                         $toggle = $this->registryEditVew->_form_private($field, $value, $fieldNode, null);
                         $this->registryEditVew->popModelOfData();
                         if (!$toggle) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } elseif ($row->{$field} != $value) {
                         if (is_callable(array($row, 'historySetMessage'))) {
                             $row->historySetMessage(ucfirst($task_parsed[0]) . ' ' . $field . ' from administration backend');
                         }
                         if ($fieldNode->attributes('class') && $fieldNode->attributes('method')) {
                             $this->registryEditVew->pushModelOfData($row);
                             $toggle = $this->registryEditVew->_form_private($field, $value, $fieldNode, null);
                             $this->registryEditVew->popModelOfData();
                             if (!$toggle) {
                                 $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                 return;
                             }
                         } elseif ($row->hasFeature('checkout')) {
                             /** @var CheckedOrderedTable $row */
                             if (!$row->isCheckedOut($_CB_framework->myId())) {
                                 $row->{$field} = $value;
                                 if ($row->check()) {
                                     if (!$row->store()) {
                                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                         return;
                                     }
                                 } else {
                                     $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                     return;
                                 }
                                 $row->checkin();
                             }
                         } else {
                             $row->{$field} = $value;
                             if ($row->check()) {
                                 if (!$row->store()) {
                                     $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                     return;
                                 }
                             } else {
                                 $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_TASK_ROW_ID_ID_BECAUSE_ERROR', 'Cannot [task] row id [id] because: [error]', array('[id]' => $dataModelValue, '[task]' => strtolower($taskName), '[error]' => $row->getError())), 'error');
                                 return;
                             }
                         }
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_TASK_SUCCESS', '{1} Row [task] successfully!|%%COUNT%% rows [task] successfully!', array('%%COUNT%%' => count($cid), '[task]' => strtolower($taskName))));
             }
             break;
         case 'editrows':
             if ($this->listFieldsRows) {
                 if (count($cid) != 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'edit')), 'error');
                     return;
                 }
                 if (isset($task_parsed[1])) {
                     $field = $task_parsed[1];
                 } else {
                     $field = 'tid';
                 }
                 if ($this->_options['view'] == 'editPlugin') {
                     $task = $this->_options['view'];
                 } else {
                     $task = 'editrow';
                 }
                 $baseUrl = 'index.php?option=' . $this->_options['option'] . '&view=' . $task;
                 if (isset($this->_options['pluginid'])) {
                     $baseUrl .= '&cid=' . $this->_options['pluginid'];
                 }
                 $url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes('name') . '&action=editrow&' . urlencode($field) . '=' . urlencode($cid[0]);
                 cbRedirect($url);
             }
             break;
         case 'deleterows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'delete')), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($row->canDelete($dataModelValue)) {
                         if (!$row->delete($dataModelValue)) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_DELETE_ROW_ID_BECAUSE_ERROR', 'Cannot delete row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } else {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_DELETE_ROW_ID_BECAUSE_ERROR', 'Cannot delete row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_DELETED_SUCCESS', 'Row deleted successfully!|%%COUNT%% rows deleted successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'batchrows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'batch')), 'error');
                     return;
                 }
                 $postData = array();
                 foreach ($this->_batchPossibilitesArray as $key => $value) {
                     // <batchprocess><batch>
                     if (!$this->isValueEmpty($value['internalvalue'])) {
                         $field = $value['valuefield'];
                         $postData[$field] = $value['internalvalue'];
                     }
                     // Reset back to null as we don't want the values reselected on display:
                     $this->_batchPossibilitesArray[$key]['value'] = null;
                     $this->_batchPossibilitesArray[$key]['internalvalue'] = $value['value'];
                 }
                 if (count($postData) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('Nothing to process'), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     /** @var $row TableInterface */
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     $rowPost = array();
                     foreach ($postData as $key => $value) {
                         if (property_exists($row, $key)) {
                             $rowPost[$key] = is_array($value) ? json_encode($value) : $value;
                         }
                     }
                     if (count($rowPost) < 1) {
                         $_CB_framework->enqueueMessage(CBTxt::T('Nothing to process'), 'error');
                         return;
                     }
                     if (!$row->bind($rowPost)) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                     if (!$row->check()) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                     if (!$row->store()) {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_BATCH_PROCESS_ROW_ID_ID_BECAUSE_ERROR', 'Cannot batch process row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_SAVED_SUCCESS', 'Row saved successfully!|%%COUNT%% rows saved successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'copyrows':
             if ($this->listFieldsRows) {
                 if (count($cid) < 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => 'copy')), 'error');
                     return;
                 }
                 $dataModelClass = $this->class;
                 foreach ($cid as $id) {
                     $dataModelValue = $id;
                     /** @var $row TableInterface */
                     $row = $this->createLoadClass($dataModelClass, $dataModelValue);
                     if (!$row) {
                         $_CB_framework->enqueueMessage(CBTxt::T('No row data found'), 'error');
                         return;
                     }
                     if ($row->canCopy()) {
                         if (!$row->copy()) {
                             $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_COPY_ROW_ID_ID_BECAUSE_ERROR', 'Cannot copy row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                             return;
                         }
                     } else {
                         $_CB_framework->enqueueMessage(CBTxt::T('CANNOT_COPY_ROW_ID_ID_BECAUSE_ERROR', 'Cannot copy row id [id] because: [error]', array('[id]' => $dataModelValue, '[error]' => $row->getError())), 'error');
                         return;
                     }
                 }
                 $_CB_framework->enqueueMessage(CBTxt::T('ROW_COUNT_COPIED_SUCCESS', 'Row copied successfully!|%%COUNT%% rows copied successfully!', array('%%COUNT%%' => count($cid))));
             }
             break;
         case 'action':
             if ($this->listFieldsRows) {
                 if (count($cid) != 1) {
                     $_CB_framework->enqueueMessage(CBTxt::T('SELECT_A_ROW_TO_TASK', 'Select a row to [task]', array('[task]' => isset($task_parsed[1]) ? $task_parsed[1] : 'action')), 'error');
                     return;
                 }
                 if (isset($task_parsed[1])) {
                     if (isset($task_parsed[2])) {
                         $field = $task_parsed[2];
                     } else {
                         $field = 'tid';
                     }
                     $baseUrl = 'index.php?option=' . $this->_options['option'] . '&view=' . $this->_options['view'];
                     if (isset($this->_options['pluginid'])) {
                         $baseUrl .= '&cid=' . $this->_options['pluginid'];
                     }
                     $url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes('name') . '&action=' . urlencode($task_parsed[1]) . '&' . urlencode($field) . '=' . urlencode($cid[0]);
                     cbRedirect($url);
                 }
             }
             break;
         default:
             break;
     }
     //TBD cbRedirect( $_CB_framework->backendUrl( 'index.php?option=com_comprofiler&task=showPlugins', $msg ) );
 }