/** * Search of AutoComplete type for fields that contained foreign keys. * * POST params: * string $term Searching value (the search will be executed by {$term}%) * string $fieldBy Field in SQL table is to search by * string $keyData Encoded into a row data about a table which is referred by the key * * @todo Security problem: there is need to restrict the search within the tables which are not denied for user (ideally - only within the controller the query is going out from). */ public function actionForeignkey() { $term = Yii::app()->request->getPost('term'); $fieldBy = Yii::app()->request->getPost('fieldBy'); $keyData = Yii::app()->request->getPost('keyData'); if(empty($term) || empty($fieldBy) || empty($keyData)) throw new CHttpException(406); $field = AAHelperUrl::decodeParam($keyData); //Primitively exclude an opportunity to access another DB, input injections and so other if(preg_match('/[^a-z_]/i', $field->options['table']) || !isset($field->options['searchBy'][$fieldBy])) throw new CHttpException(406); $data = array(); $matches = array(); $q = Yii::app()->{AADb::$dbConnection}->createCommand() ->from($field->options['table']) ->select(array_merge(array($field->options['pk']), array_keys($field->options['select']))) ->where(array('LIKE', "{$field->options['table']}.{$fieldBy}", AADb::metaToLike($term))) ->order($fieldBy); $result = $q->queryAll(); foreach($result as $r) { $label = ""; foreach($r as $kField=>$value) { if($kField != $field->options['pk']) $label .= ($label ? ' - ' : '').$value; } $matches[] = array('label'=>$label, 'value'=>$r[$field->options['pk']]); } echo CJSON::encode($matches); }
public function run() { $currentPageNum = 1; if($this->total > $this->maxPerPage) { //If there`s no nessecary to paginate $currentPageNum = floor($this->total / $this->maxPerPage); if(($this->total % $this->maxPerPage) != 0) $currentPageNum++; //round to greater } else { return; //no pagination } $dec = floor(($this->currentPage-1) / 10); //quantity of tens if($dec > 0) { echo CHtml::link('1', AAHelperUrl::replaceParam(Yii::app()->request->requestUri, 'page', 1)).' … '; if($dec > 2) { $pcntr = floor($dec/2)*10; echo CHtml::link('1', AAHelperUrl::replaceParam(Yii::app()->request->requestUri, 'page', $pcntr)).' … '; } } for($i = 1; $i < 12; $i++) { $pn = ($dec * 10) + $i; if($pn <= $currentPageNum) { //Perhaps will finish earlier if($i == 11) { //to next ten echo CHtml::link(Yii::t('AutoAdmin.common', 'More'), AAHelperUrl::replaceParam(Yii::app()->request->requestUri, 'page', $pn), array('class'=>'more')); } else { if($pn != $this->currentPage) { //active, unactive... echo CHtml::link($pn, AAHelperUrl::replaceParam(Yii::app()->request->requestUri, 'page', $pn), array('class'=>'pagenum page'.$i)); } else { echo CHtml::tag('span', array('class'=>'pagenum active'), $pn); } } } } }
<tr> <th><?php echo Yii::t('AutoAdmin.generator', 'SQL table name')?></th> <th><?php echo Yii::t('AutoAdmin.generator', 'Columns')?></th> </tr> </thead> <tbody> <?php if(!empty($tables)) { $url = $this->createUrl('aagenerator/table'); foreach($tables as $tableName=>$table) { ?> <tr> <td> <a href="<?php echo AAHelperUrl::addParam($url, 'table', $tableName);?>"><?php echo $tableName?></a></td> <td> <?php if(!empty($table->columns)) echo implode(', ', array_slice(array_keys($table->columns), 0, 5)); if(count($table->columns) > 5) echo ', …'; ?> </td> </tr> <?php } } ?> </tbody> </table>
/** * Outputs results of operations. * @param array $dataToPass Specific data to pass into the view script. */ protected function resultMode($dataToPass=array()) { $dataToPass['redirectURL'] = AAHelperUrl::stripParam(Yii::app()->request->requestUri, array('action', 'sure')); foreach($this->_data->pk as $pkField=>$value) $dataToPass['redirectURL'] = AAHelperUrl::stripParam($dataToPass['redirectURL'], "id[{$pkField}]"); $this->_controller->render($this->viewsPath.'editResult', array_merge($dataToPass, $this->_viewData)); }
?> <th></th> </tr> </thead> <tbody> <?php foreach($dataRows as $rowI=>$dataRow) { ?> <tr id="tr_<?php echo (1)?>"> <td class="row-number"><span><?php echo (($rowI+1) + $rowsOnPage*($currentPage-1))?>.</span></td> <?php if(!empty($urlSub)) { ?> <td class="subtable"><?php echo CHtml::link('-', AAHelperUrl::addParam($urlSub, 'bk', $dataRow->pk))?></td> <?php } foreach($dataRow as $k=>$field) { //Output fields that were set for show if(!$field->showInList) continue; ?> <td class="t-<?php echo $field->type?>"> <?php if(is_null($field->value)) { ?><span class="null">NULL</span><?php } else
public function formInput(&$controller, $tagOptions=array()) { ob_start(); $inputName = $this->formInputName(); $inputID = "i_{$inputName}"; echo CHtml::label($this->label, $inputID); echo CHtml::tag('br'); $tagOptions['id'] = $inputID; $value = (!is_null($this->value) ? $this->value : $this->defaultValue); if(!$this->isReadonly && $this->getPossibleValuesCount() <= $this->options['limit']) { if(!$this->allowNull) $tagOptions['required'] = 'required'; echo CHtml::dropDownList($inputName, $value, $this->getOptValues(), $tagOptions); } else { echo CHtml::dropDownList('', $value, array($this->getTitleByFields($this->selectDefault())), array('disabled'=>true)); echo CHtml::hiddenField($inputName, $value); if(!$this->isReadonly && !empty($this->options['searchBy'])) { $options = array(); foreach($this->options['searchBy'] as $field=>$label) { $options[$field] = $label; } ?> <div class="foreign-search"> <?php echo CHtml::label('', "foreignSearchQ_{$this->name}"); echo CHtml::dropDownList(null, null, $options, array('id'=>"foreignSearchBy_{$this->name}")).':'; //Searching the ForeignKey value $controller->widget('zii.widgets.jui.CJuiAutoComplete', array( 'name' => '', 'id' => "foreignSearchQ_{$this->name}", 'source' => 'js: foreignKeyQuery', 'value' => '', 'options' => array( 'minLength'=>1, 'delay' => 700, 'select'=>'js: foreignKeySelected', //these are the user defined variables for multi-params query 'sourceUrl' => Yii::app()->request->baseUrl.'/aaajax/foreignkey/', 'extraParams' => array('keyData'=>AAHelperUrl::encodeParam($this)), ), )); ?> </div> <?php } } return ob_get_clean(); }
<?php } else { $bkp = $bindKeysParent; array_push($bkp, $bindKeys); foreach($iframes as $iframe) { ?> <div class="item"> <?php echo CHtml::tag('iframe', array( 'src' => AAHelperUrl::update(Yii::app()->request->requestUri, array('id', 'action'), array( 'foreign' => $iframe['action'], 'bkp' => $bkp, 'bk' => $fields->pk, ) )), null, true); if(!empty($iframe['foreign']->description)) { ?><div class="desc"><?php echo $iframe['foreign']->description?></div><?php } ?> </div> <?php } } } echo CHtml::submitButton(Yii::t('AutoAdmin.common', 'Save'), array('name'=>null));
/** * Adds a level into the breadcrumbs, converting service parameters in the link and extracting a label in help with SQL-query that is preliminary defined by $this->query. * @param int $level Zero or negative value as step downwards. * @param string $action Controller's action to link to. * @param string $label Label for breadcrumb. * @param bool $labelNonStatic Forces to make a query and use $label as postfix for the found label. * @return string A final breadcrumb label. * @throws AAException */ public function addLevel($level, $action, $label=null, $labelNonStatic=false) { if($level > 0) return; if($labelNonStatic || is_null($label)) { if(!isset($this->query->command->from) || !isset($this->query->command->select)) throw new AAException(Yii::t('AutoAdmin.errors', 'Breadcrumbs can be generated only after AABreadcrumbs->query->select()->from() initializing. Or use call with static label.')); if(!$this->query->command->where) //otherwise means a user set where by himself. { if($level == 0) { $bk = Yii::app()->request->getParam('bk'); } else { $bkp = Yii::app()->request->getParam('bkp'); if(!isset($bkp[abs($level)-1])) throw new AAException(Yii::t('AutoAdmin.errors', 'Incorrect breadcrumbs level.')); $bk = $bkp[abs($level)-1]; } if(is_null($bk) || !is_array($bk)) throw new AAException(Yii::t('AutoAdmin.errors', 'Auto-generation of the breadcrumbs can be done only with the default inside-controller navigation.')); $where = array('AND'); $params = array(); foreach($bk as $pk=>$pkValue) { $where[] = "{$pk}=:{$pk}"; $params[":{$pk}"] = $pkValue; } $this->query->where($where, $params); $this->query->command->limit(1); } $newLabel = $this->query->command->queryScalar(); $label = ($label && $labelNonStatic) ? "{$newLabel}. {$label}" : $newLabel; } if($level == 0) { $this->controller->breadcrumbs[] = $this->controller->pageTitle = AAHelperText::ucfirst($label).'. '.$this->controller->pageTitle; } else { $params = AAHelperUrl::uriToParamsArray(Yii::app()->request->getRequestUri()); if($params) { //Removing GET-params which relate to the current page $paramsToExclude = array('page', 'sortBy', 'searchBy', 'searchQ', 'msg', 'action', 'bk', 'bkp', 'id', 'foreign'); foreach($paramsToExclude as $param) { if(array_key_exists($param, $params)) unset($params[$param]); if(!$params) break; else { foreach($params as $key=>$value) { if(preg_match("/^{$param}\[/i", $key)) { unset($params[$key]); continue 2; } } } } } $link = "../{$action}/"; $bkp = Yii::app()->request->getParam('bkp', array()); if(isset($bkp[0])) { foreach($bkp as $pkLevel=>$pk) { if($pkLevel < abs($level)-1) continue; if($pkLevel==0) $paramBase = 'bk'; else $paramBase = 'bkp['.($pkLevel-1).']'; foreach($pk as $keyField=>$keyValue) { $params[$paramBase.'['.$keyField.']'] = $keyValue; } } } if($params) { $paramStr = ''; foreach($params as $param=>$value) $paramStr .= ($paramStr ? '&' : '?').$param.'='.$value; $link .= $paramStr; } $this->insertToPosition((count($this->controller->breadcrumbs)+$level), $label, $link); } $this->query->command->reset(); return $label; }
<?php $actionURL = AAHelperUrl::update($baseURL, array('searchQ', 'searchBy')); $getParams = AAHelperUrl::uriToParamsArray($actionURL); if($getParams) $actionURL = AAHelperUrl::update($actionURL, array_keys($getParams)); echo CHtml::form($actionURL, 'get', array('id'=>'search-panel')); foreach($getParams as $param=>$value) echo CHtml::hiddenField($param, $value); echo CHtml::label(Yii::t('AutoAdmin.common', 'Search').':', 'searchQ'); echo CHtml::textField('searchQ', (isset($searchOptions['query']) && !is_array($searchOptions['query']) ? $searchOptions['query'] : ''), array('id'=>'searchQ')); $inSearch = array(); $selectedIndex = null; foreach($fields as $k=>$field) { if(!empty($field->options['inSearch'])) { $inSearch[$k] = $field->label; if(!empty($searchOptions['field']) && $searchOptions['field']->name == $field->name) $selectedIndex = $k; } } echo CHtml::dropDownList('searchBy', $selectedIndex, $inSearch); echo CHtml::submitButton('OK', array('name'=>null, 'title'=>Yii::t('AutoAdmin.common', 'Search'))); echo CHtml::resetButton(Yii::t('AutoAdmin.common', 'Reset'), array('name'=>null, 'title'=>Yii::t('AutoAdmin.common', 'Reset'))); echo CHtml::closeTag('form'); ?>