diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f3e5cc3..5b99c31 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,13 @@ - - - + + + @@ -63,97 +63,35 @@ - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - + + + + + + + + + + @@ -167,14 +105,6 @@ @@ -231,7 +169,7 @@ @@ -314,6 +252,20 @@ + + + + + + + + + + @@ -385,8 +337,30 @@ + - + + + + + + + + + + @@ -412,7 +386,7 @@ - - - - - - - - - - @@ -808,12 +720,12 @@ - + - + @@ -822,15 +734,15 @@ - + - + @@ -858,331 +770,129 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + - - - + - - - - - - - - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - + - - - - - - - - - - + - - - + - - - + - - - + - - - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1194,46 +904,187 @@ - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DB_Changes.txt b/DB_Changes.txt index b35b880..7f00093 100644 --- a/DB_Changes.txt +++ b/DB_Changes.txt @@ -8,4 +8,6 @@ programme -> Niripsa[visible] = 0 programme -> ms4_programs idx_info -> ms4_log -idx_info -> new columns + full content change \ No newline at end of file +idx_info -> new columns + full content change + +othervalues -> ms4_othervalues \ No newline at end of file diff --git a/www/css/styles.css b/www/css/styles.css index 31d5d71..9ee7da9 100644 --- a/www/css/styles.css +++ b/www/css/styles.css @@ -39,6 +39,20 @@ margin-bottom: 0px; } +.cstm-main-navbar-highlight > a { + color: yellow !important; + background-color: gray; + border-radius: 6px; + margin-left: 20px; +} + +.cstm-main-navbar-highlight > a:hover { + color: black !important; + background-color: lightgray !important;; + border-radius: 6px; + margin-left: 20px; +} + img.grayscale { /* Firefox 10+, Firefox on Android */ filter: url("data:image/svg+xml;utf8,#grayscale"); diff --git a/www/protected/components/UserIdentity.php b/www/protected/components/UserIdentity.php index 9a25389..4010097 100644 --- a/www/protected/components/UserIdentity.php +++ b/www/protected/components/UserIdentity.php @@ -19,7 +19,7 @@ class UserIdentity extends CUserIdentity { $connection = Yii::app()->db; - $command=$connection->createCommand("SELECT SValue FROM othervalues WHERE Name = 'AdminPassword'"); + $command=$connection->createCommand("SELECT SValue FROM {{othervalues}} WHERE Name = 'AdminPassword'"); $pw = $command->queryScalar(); $users=array( diff --git a/www/protected/config/main.php b/www/protected/config/main.php index f9365f3..910b9d5 100644 --- a/www/protected/config/main.php +++ b/www/protected/config/main.php @@ -68,8 +68,8 @@ return ArrayX::merge( 'programs/' => 'programs/index', 'programs/view/' => 'programs/view', - 'log' => ['msmain/log', 'defaultParams' => ['logid' => '-1']], - 'log/' => ['msmain/log', 'defaultParams' => ['logid' => '-1']], + 'log/' => ['log/index', 'defaultParams' => ['logid' => '-1']], + 'log/' => ['log/index', 'defaultParams' => ['logid' => '-1']], 'downloads/details.php' => 'programs/index', // Compatibility 'downloads/downloads.php' => 'programs/index', // Compatibility diff --git a/www/protected/controllers/LogController.php b/www/protected/controllers/LogController.php new file mode 100644 index 0000000..07c350a --- /dev/null +++ b/www/protected/controllers/LogController.php @@ -0,0 +1,195 @@ +array('index', 'ajaxMarkdownPreview'), + 'users'=>array('*'), + ), + array('allow', + 'actions'=>array('create','update','admin','delete','view'), + 'users'=>array('admin'), + ), + array('deny', + 'users'=>array('*'), + ), + ); + } + + /** + * Lists all models. + */ + public function actionIndex($logid) + { + $this->layout='//layouts/main'; + + $criteria = new CDbCriteria; + $criteria->order = "date DESC"; + + $all = Log::model()->findAll($criteria); + /* @var $all Log[] */ + + $this->render('index', + [ + 'logs' => $all, + 'logid' => $logid, + ]); + } + + public function actionAjaxMarkdownPreview() { + if(Yii::app()->request->isAjaxRequest){ + $this->renderPartial('_ajaxMarkdownPreview', + [ + 'content' => $_POST['content'], + ], + false, true); + } else { + throw new CHttpException(400,'Invalid request. This is a Ajax only action.'); + } + } + + /** + * Displays a particular model. + * @param integer $id the ID of the model to be displayed + */ + public function actionView($id) + { + $this->render('view',array( + 'model'=>$this->loadModel($id), + )); + } + + /** + * Creates a new model. + * If creation is successful, the browser will be redirected to the 'view' page. + */ + public function actionCreate() + { + $model=new Log; + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Log'])) + { + $model->attributes=$_POST['Log']; + if($model->save()) + $this->redirect(array('view','id'=>$model->ID)); + } + + $this->render('create',array( + 'model'=>$model, + )); + } + + /** + * Updates a particular model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id the ID of the model to be updated + */ + public function actionUpdate($id) + { + $model=$this->loadModel($id); + + // Uncomment the following line if AJAX validation is needed + // $this->performAjaxValidation($model); + + if(isset($_POST['Log'])) + { + $model->attributes=$_POST['Log']; + if($model->save()) + $this->redirect(array('view','id'=>$model->ID)); + } + + $this->render('update',array( + 'model'=>$model, + )); + } + + /** + * Deletes a particular model. + * If deletion is successful, the browser will be redirected to the 'admin' page. + * @param integer $id the ID of the model to be deleted + * @throws CHttpException + */ + public function actionDelete($id) + { + if (Yii::app()->request->isPostRequest) { + // we only allow deletion via POST request + $this->loadModel($id)->delete(); + + // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser + if (!isset($_GET['ajax'])) { + $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); + } + } else { + throw new CHttpException(400,'Invalid request. Please do not repeat this request again.'); + } + } + + /** + * Manages all models. + */ + public function actionAdmin() + { + $model=new Log('search'); + $model->unsetAttributes(); // clear any default values + if(isset($_GET['Log'])) + $model->attributes=$_GET['Log']; + + $this->render('admin',array( + 'model'=>$model, + )); + } + + /** + * Returns the data model based on the primary key given in the GET variable. + * If the data model is not found, an HTTP exception will be raised. + * @param integer $id the ID of the model to be loaded + * @return Log the loaded model + * @throws CHttpException + */ + public function loadModel($id) + { + $model=Log::model()->findByPk($id); + if($model===null) + throw new CHttpException(404,'The requested page does not exist.'); + return $model; + } + + /** + * Performs the AJAX validation. + * @param Log $model the model to be validated + */ + protected function performAjaxValidation($model) + { + if(isset($_POST['ajax']) && $_POST['ajax']==='log-form') + { + echo CActiveForm::validate($model); + Yii::app()->end(); + } + } +} diff --git a/www/protected/controllers/MSMainController.php b/www/protected/controllers/MSMainController.php index 6f53be7..9f16edd 100644 --- a/www/protected/controllers/MSMainController.php +++ b/www/protected/controllers/MSMainController.php @@ -2,6 +2,38 @@ class MSMainController extends MSController { + /** + * @return array action filters + */ + public function filters() + { + return array( + 'accessControl', + ); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', + 'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout'), + 'users'=>array('*'), + ), + array('allow', + 'actions'=>array('admin'), + 'users'=>array('admin'), + ), + array('deny', + 'users'=>array('*'), + ), + ); + } + public function actionIndex() { $criteria = new CDbCriteria; @@ -77,7 +109,7 @@ class MSMainController extends MSController public function actionLogin() { - $model=new LoginForm; + $model = new LoginForm(); // if it is ajax validation request if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') @@ -98,6 +130,11 @@ class MSMainController extends MSController $this->render('login', array('model'=>$model)); } + public function actionAdmin() + { + $this->render('admin', array()); + } + public function actionLogout() { Yii::app()->user->logout(); @@ -105,16 +142,6 @@ class MSMainController extends MSController } public function actionLog($logid) { - $criteria = new CDbCriteria; - $criteria->order = "date DESC"; - $all = Log::model()->findAll($criteria); - /* @var $all Log[] */ - - $this->render('log', - [ - 'logs' => $all, - 'logid' => $logid, - ]); } } \ No newline at end of file diff --git a/www/protected/views/layouts/main.php b/www/protected/views/layouts/main.php index f7cec48..cf639d2 100644 --- a/www/protected/views/layouts/main.php +++ b/www/protected/views/layouts/main.php @@ -47,10 +47,10 @@ ['label' => 'Programs', 'url' => '/programs/', 'active' => ($this->selectedNav === 'prog')], ['label' => '', 'items' => ProgramHelper::GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']], ['label' => 'About', 'url' => '/about', 'active' => ($this->selectedNav === 'about')], - ['label' => '[[Log "'.Yii::app()->user->name.'" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest] + ['label' => '[[Log "'.Yii::app()->user->name.'" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest, 'htmlOptions' => ['class' => 'cstm-main-navbar-highlight']] ], ], - MsHtml::navbarSearchForm('search', '', + MsHtml::navbarSearchForm('/search', '', [ 'class' => 'pull-right', 'placeholder' => 'Search', @@ -89,10 +89,6 @@ - - - - \ No newline at end of file diff --git a/www/protected/views/log/_ajaxMarkdownPreview.php b/www/protected/views/log/_ajaxMarkdownPreview.php new file mode 100644 index 0000000..b35821e --- /dev/null +++ b/www/protected/views/log/_ajaxMarkdownPreview.php @@ -0,0 +1,7 @@ +beginWidget('CMarkdown'); + +echo $content; + +$this->endWidget(); \ No newline at end of file diff --git a/www/protected/views/log/_form.php b/www/protected/views/log/_form.php new file mode 100644 index 0000000..cb3b7e3 --- /dev/null +++ b/www/protected/views/log/_form.php @@ -0,0 +1,52 @@ + + +
+ + beginWidget('bootstrap.widgets.TbActiveForm', array( + 'id'=>'log-form', + // Please note: When you enable ajax validation, make sure the corresponding + // controller action is handling ajax validation correctly. + // There is a call to performAjaxValidation() commented in generated controller code. + // See class documentation of CActiveForm for details on this. + 'enableAjaxValidation'=>false, +)); ?> + +

Fields with * are required.

+ + errorSummary($model); ?> + + textFieldControlGroup($model,'date',array('span'=>5, 'value'=>date('Y-m-d'))); ?> + + textAreaControlGroup($model,'title',array('rows'=>6,'span'=>8)); ?> + + textAreaControlGroup($model,'content',array('rows'=>6,'span'=>8)); ?> + + 'POST', + 'data' => ['content'=> 'js: $("#Log_content").val()'], + 'update' => '#markdownAjaxContent', + 'error'=>'function(msg){alert("An error has happened");}', + ]); ?> + +
+
+ +
+ renderPartial('_ajaxMarkdownPreview', ['content' => $model->content, ], false, true); ?> +
+ +
+ isNewRecord ? 'Create' : 'Save',array( + 'color'=>MsHtml::BUTTON_COLOR_PRIMARY, + 'size'=>MsHtml::BUTTON_SIZE_LARGE, + )); ?> +
+ + endWidget(); ?> + +
\ No newline at end of file diff --git a/www/protected/views/log/_search.php b/www/protected/views/log/_search.php new file mode 100644 index 0000000..0b0c40c --- /dev/null +++ b/www/protected/views/log/_search.php @@ -0,0 +1,28 @@ + + +
+ + beginWidget('bootstrap.widgets.TbActiveForm', array( + 'action'=>Yii::app()->createUrl($this->route), + 'method'=>'get', +)); ?> + + textFieldControlGroup($model,'ID',array('span'=>5)); ?> + + textFieldControlGroup($model,'date',array('span'=>5)); ?> + + textAreaControlGroup($model,'title',array('rows'=>6,'span'=>8)); ?> + + textAreaControlGroup($model,'content',array('rows'=>6,'span'=>8)); ?> + +
+ MsHtml::BUTTON_COLOR_PRIMARY,));?> +
+ + endWidget(); ?> + +
\ No newline at end of file diff --git a/www/protected/views/log/_view.php b/www/protected/views/log/_view.php new file mode 100644 index 0000000..03a4951 --- /dev/null +++ b/www/protected/views/log/_view.php @@ -0,0 +1,25 @@ + + +
+ + getAttributeLabel('ID')); ?>: + ID),array('view','id'=>$data->ID)); ?> +
+ + getAttributeLabel('date')); ?>: + date); ?> +
+ + getAttributeLabel('title')); ?>: + title); ?> +
+ + getAttributeLabel('content')); ?>: + content); ?> +
+ + +
\ No newline at end of file diff --git a/www/protected/views/log/admin.php b/www/protected/views/log/admin.php new file mode 100644 index 0000000..e711fad --- /dev/null +++ b/www/protected/views/log/admin.php @@ -0,0 +1,58 @@ +breadcrumbs=array( + 'Logs'=>array('index'), + 'Manage', +); + +$this->menu=array( + array('label'=>'List Log', 'url'=>array('index')), + array('label'=>'Create Log', 'url'=>array('create')), +); + +Yii::app()->clientScript->registerScript('search', " +$('.search-button').click(function(){ + $('.search-form').toggle(); + return false; +}); +$('.search-form form').submit(function(){ + $('#log-grid').yiiGridView('update', { + data: $(this).serialize() + }); + return false; +}); +"); +?> + +

Manage Logs

+ +

+ You may optionally enter a comparison operator (<, <=, >, >=, + <> +or =) at the beginning of each of your search values to specify how the comparison should be done. +

+ +'search-button btn')); ?> + + +widget('bootstrap.widgets.TbGridView',array( + 'id'=>'log-grid', + 'dataProvider'=>$model->search(), + 'filter'=>$model, + 'columns'=>array( + 'ID', + 'date', + 'title', + 'content', + array( + 'class'=>'bootstrap.widgets.TbButtonColumn', + ), + ), +)); ?> \ No newline at end of file diff --git a/www/protected/views/log/create.php b/www/protected/views/log/create.php new file mode 100644 index 0000000..e674a16 --- /dev/null +++ b/www/protected/views/log/create.php @@ -0,0 +1,20 @@ + + +breadcrumbs=array( + 'Logs'=>array('index'), + 'Create', +); + +$this->menu=array( + array('label'=>'List Log', 'url'=>array('index')), + array('label'=>'Manage Log', 'url'=>array('admin')), +); +?> + +

Create Log

+ +renderPartial('_form', array('model'=>$model)); ?> \ No newline at end of file diff --git a/www/protected/views/log/index.php b/www/protected/views/log/index.php new file mode 100644 index 0000000..119610b --- /dev/null +++ b/www/protected/views/log/index.php @@ -0,0 +1,40 @@ +pageTitle=Yii::app()->name; + +$this->breadcrumbs= + [ + 'Log' + ]; + +$this->selectedNav = ''; + +?> + +
+ + + +
+ widget('ExpandedLogHeader', + [ + 'date' => new DateTime($logelem->date), + 'caption' => $logelem->title, + 'content' => $logelem->content, + 'collapseID' => $i, + 'collapseOwner' => '#lca', + 'collapseOpen' => ($logelem->ID == $logid), + ]); + } + ?> +
+ +
\ No newline at end of file diff --git a/www/protected/views/log/update.php b/www/protected/views/log/update.php new file mode 100644 index 0000000..c5501c1 --- /dev/null +++ b/www/protected/views/log/update.php @@ -0,0 +1,23 @@ + + +breadcrumbs=array( + 'Logs'=>array('index'), + $model->title=>array('view','id'=>$model->ID), + 'Update', +); + +$this->menu=array( + array('label'=>'List Log', 'url'=>array('index')), + array('label'=>'Create Log', 'url'=>array('create')), + array('label'=>'View Log', 'url'=>array('view', 'id'=>$model->ID)), + array('label'=>'Manage Log', 'url'=>array('admin')), +); +?> + +

Update Log ID; ?>

+ +renderPartial('_form', array('model'=>$model)); ?> \ No newline at end of file diff --git a/www/protected/views/log/view.php b/www/protected/views/log/view.php new file mode 100644 index 0000000..6399c70 --- /dev/null +++ b/www/protected/views/log/view.php @@ -0,0 +1,34 @@ + + +breadcrumbs=array( + 'Logs'=>array('index'), + $model->title, +); + +$this->menu=array( + array('label'=>'List Log', 'url'=>array('index')), + array('label'=>'Create Log', 'url'=>array('create')), + array('label'=>'Update Log', 'url'=>array('update', 'id'=>$model->ID)), + array('label'=>'Delete Log', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->ID),'confirm'=>'Are you sure you want to delete this item?')), + array('label'=>'Manage Log', 'url'=>array('admin')), +); +?> + +

View Log #ID; ?>

+ +widget('zii.widgets.CDetailView',array( + 'htmlOptions' => array( + 'class' => 'table table-striped table-condensed table-hover', + ), + 'data'=>$model, + 'attributes'=>array( + 'ID', + 'date', + 'title', + 'content', + ), +)); ?> \ No newline at end of file diff --git a/www/protected/views/msmain/debugerror.php b/www/protected/views/msmain/debugerror.php index e6df265..f52d332 100644 --- a/www/protected/views/msmain/debugerror.php +++ b/www/protected/views/msmain/debugerror.php @@ -1,5 +1,5 @@ pageTitle=Yii::app()->name . ' - Error'; diff --git a/www/protected/views/msmain/error.php b/www/protected/views/msmain/error.php index d66ffa5..4550872 100644 --- a/www/protected/views/msmain/error.php +++ b/www/protected/views/msmain/error.php @@ -1,5 +1,5 @@ pageTitle=Yii::app()->name . ' - Error'; diff --git a/www/protected/views/msmain/log.php b/www/protected/views/msmain/log.php deleted file mode 100644 index a660b6f..0000000 --- a/www/protected/views/msmain/log.php +++ /dev/null @@ -1,40 +0,0 @@ -pageTitle=Yii::app()->name; - -$this->breadcrumbs= - [ - 'Log' - ]; - -$this->selectedNav = ''; - -?> - -
- - - -
- widget('ExpandedLogHeader', - [ - 'date' => new DateTime($logelem->date), - 'caption' => $logelem->title, - 'content' => $logelem->content, - 'collapseID' => $i, - 'collapseOwner' => '#lca', - 'collapseOpen' => ($logelem->ID == $logid), - ]); - } - ?> -
- -
\ No newline at end of file diff --git a/www/protected/views/msmain/login.php b/www/protected/views/msmain/login.php index 0a4dc6a..d6f2ba4 100644 --- a/www/protected/views/msmain/login.php +++ b/www/protected/views/msmain/login.php @@ -1,5 +1,5 @@