PageRenderTime 48ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/auth/controllers/AdminController.php

https://github.com/najeebbuzinessware/socialintranet
PHP | 738 lines | 694 code | 7 blank | 37 comment | 39 complexity | 5f61f593eacb3d752ef85d7ca7bf848e MD5 | raw file
  1. <?php
  2. class AdminController extends MemberController
  3. {
  4. /*
  5. * Filter for the validation to check Admin user type
  6. */
  7. public function filters( )
  8. {
  9. return array( array( 'common.filters.AdminUserAuthFilter' ) );
  10. }
  11. public function actionListUser( )
  12. {
  13. //$this->_checkAuth();
  14. $model = new TblSysUsers();
  15. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'users-form')
  16. {
  17. echo CActiveForm::validate( $model );
  18. Yii::app()->end();
  19. }
  20. if (strlen( $_POST['btnsave'] ) > 0)
  21. {
  22. if (isset( $_POST['TblSysUsers'] ))
  23. {
  24. // if it is ajax validation request
  25. $model = new TblSysUsers();
  26. $model->attributes = $_POST['TblSysUsers'];
  27. $model->MId = Yii::app()->user->MId;
  28. $model->WeightageId = $_POST['TblSysUsers']['WeightageId'];
  29. // validate user input and redirect to the previous page if valid
  30. if ($model->save())
  31. {
  32. // Update TblAuth Assignment
  33. if (count( $_POST['groups'] ) > 0)
  34. {
  35. foreach ( $_POST['groups'] as $key => $value )
  36. {
  37. $moduleaccess = new TblSysAuthAssignment();
  38. $moduleaccess->itemname = $value;
  39. $moduleaccess->MId = Yii::app()->user->MId;
  40. $moduleaccess->userid = $model->Userid;
  41. $moduleaccess->save();
  42. }
  43. // Update User Menu Cache
  44. //$this->UserModuleCache( $model->Userid, Yii::app()->user->MId );
  45. }
  46. Yii::app()->session['notice'] = Yii::t( 'translate', 'User Created' );
  47. Yii::app()->session['ntype'] = 'success';
  48. $this->redirect( "/admin/listUser" );
  49. } else
  50. {
  51. $msg = "<h1>Error</h1>";
  52. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  53. $msg .= "<ul>";
  54. foreach ( $model->errors as $attribute => $attr_errors )
  55. {
  56. $msg .= "<li>Attribute: $attribute</li>";
  57. $msg .= "<ul>";
  58. foreach ( $attr_errors as $attr_error )
  59. $msg .= "<li>$attr_error</li>";
  60. $msg .= "</ul>";
  61. }
  62. $msg .= "</ul>";
  63. $this->_sendResponse( 500, $msg );
  64. }
  65. }
  66. }
  67. $groupdata = TblSysAuthItem::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'type' => '2' ) );
  68. if (count( $groupdata ) > 0)
  69. {
  70. foreach ( $groupdata as $key => $value )
  71. {
  72. $group[$value['name']] = $value['name'];
  73. }
  74. }
  75. $criteria = new CDbCriteria();
  76. $criteria->select = " LEFT( Name, 1 ) AS username";
  77. $criteria->condition = "IsDelete=0 and MId = '" . Yii::app()->user->MId . "'";
  78. $criteria->order = "username ASC";
  79. $criteria->group = "username";
  80. $total = TblSysUsers::model()->count( $criteria );
  81. $pages = new CPagination( $total );
  82. $pages->pageSize = 5;
  83. $pages->applyLimit( $criteria );
  84. $usermodel = TblSysUsers::model()->findAll( $criteria );
  85. $alphacriteria = new CDbCriteria();
  86. $alphacriteria->select = " LEFT(Name, 1 ) AS username";
  87. $alphacriteria->condition = "IsDelete=0 and MId = '" . Yii::app()->user->MId . "'";
  88. $alphacriteria->group = "username";
  89. $alphacriteria->order = "username ASC";
  90. $alphasort = TblSysUsers::model()->findAll( $alphacriteria );
  91. $this->render( 'listUser', array( "model" => $model, "usermodel" => $usermodel, 'group' => $group, "pages" => $pages, "alphasort" => $alphasort ) );
  92. }
  93. public function actionCreateuser( )
  94. {
  95. $this->_checkAuth();
  96. // collect user input data
  97. $model = new TblSysUsers();
  98. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'users-form')
  99. {
  100. echo CActiveForm::validate( $model );
  101. Yii::app()->end();
  102. }
  103. if (strlen( $_POST['btnsave'] ) > 0)
  104. {
  105. if (isset( $_POST['TblSysUsers'] ))
  106. {
  107. // if it is ajax validation request
  108. $model = new TblSysUsers();
  109. $model->attributes = $_POST['TblSysUsers'];
  110. $model->MId = Yii::app()->user->MId;
  111. // validate user input and redirect to the previous page if valid
  112. if ($model->save())
  113. {
  114. // Update TblAuth Assignment
  115. if (count( $_POST['groups'] ) > 0)
  116. {
  117. foreach ( $_POST['groups'] as $key => $value )
  118. {
  119. $moduleaccess = new TblSysAuthAssignment();
  120. $moduleaccess->itemname = $value;
  121. $moduleaccess->MId = Yii::app()->user->MId;
  122. $moduleaccess->userid = $model->Userid;
  123. $moduleaccess->save();
  124. }
  125. // Update User Menu Cache
  126. //$this->UserModuleCache( $model->Userid, Yii::app()->user->MId );
  127. }
  128. Yii::app()->session['notice'] = Yii::t( 'translate', 'User Created' );
  129. Yii::app()->session['ntype'] = 'success';
  130. $this->redirect( "/admin/listUser" );
  131. } else
  132. {
  133. $msg = "<h1>Error</h1>";
  134. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  135. $msg .= "<ul>";
  136. foreach ( $model->errors as $attribute => $attr_errors )
  137. {
  138. $msg .= "<li>Attribute: $attribute</li>";
  139. $msg .= "<ul>";
  140. foreach ( $attr_errors as $attr_error )
  141. $msg .= "<li>$attr_error</li>";
  142. $msg .= "</ul>";
  143. }
  144. $msg .= "</ul>";
  145. $this->_sendResponse( 500, $msg );
  146. }
  147. }
  148. }
  149. $groupdata = TblSysAuthItem::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'type' => '2' ) );
  150. foreach ( $groupdata as $key => $value )
  151. {
  152. $group[$value['name']] = $value['name'];
  153. }
  154. // $this->render("_createuser",array("model"=>$model,'group'=>$group));
  155. }
  156. public function actionUpdateuser($id = NULL)
  157. {
  158. $this->_checkAuth();
  159. if ($id == "")
  160. {
  161. $id = $_POST['TblSysUsers']['Userid'];
  162. }
  163. $criteria = new CDbCriteria( array( 'condition' => 'UserId = ' . $id . ' AND MId = ' . Yii::app()->user->MId ) );
  164. $model = TblSysUsers::model()->find( $criteria );
  165. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'users-form')
  166. {
  167. echo CActiveForm::validate( $model );
  168. Yii::app()->end();
  169. }
  170. if (strlen( $_POST['btnsave'] ) > 0)
  171. {
  172. if (isset( $_POST['TblSysUsers'] ))
  173. {
  174. // if it is ajax validation request
  175. $model = TblSysUsers::model()->findByPk( $_POST['TblSysUsers']['Userid'] );
  176. $model->attributes = $_POST['TblSysUsers'];
  177. $model->ModifiedOn = time();
  178. $model->MId = Yii::app()->user->MId;
  179. // validate user input and redirect to the previous page if valid
  180. if ($model->save())
  181. {
  182. TblSysAuthAssignment::model()->deleteAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'userid' => $_POST['TblUsers']['Userid'] ) );
  183. if (count( $_POST['groups'] ) > 0)
  184. {
  185. // Update TblAuth Assignment
  186. foreach ( $_POST['groups'] as $key => $value )
  187. {
  188. $moduleaccess = new TblSysAuthAssignment();
  189. $moduleaccess->itemname = $value;
  190. $moduleaccess->MId = Yii::app()->user->MId;
  191. $moduleaccess->userid = $model->Userid;
  192. $moduleaccess->save();
  193. }
  194. // Update User Menu Cache
  195. //$this->UserModuleCache( $_POST['TblUsers']['Userid'], Yii::app()->user->MId );
  196. }
  197. Yii::app()->session['notice'] = Yii::t( 'translate', 'User Updated' );
  198. Yii::app()->session['ntype'] = 'success';
  199. $this->redirect( "/admin/listUser" );
  200. }
  201. }
  202. }
  203. $groupdata = TblSysAuthItem::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'type' => '2' ) );
  204. foreach ( $groupdata as $key => $value )
  205. {
  206. $group[$value['name']] = $value['name'];
  207. }
  208. // Get User Assigned Group List
  209. $GroupList = TblSysAuthAssignment::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'userid' => $id ) );
  210. foreach ( $GroupList as $key => $value )
  211. {
  212. $AssignGroup[] = $value['itemname'];
  213. }
  214. $this->render( "_createuser", array( "model" => $model, 'group' => $group, 'groups' => $AssignGroup ) );
  215. }
  216. public function actionUpload( )
  217. {
  218. Yii::import( "common.extensions.EAjaxUpload.qqFileUploader" );
  219. //$folder = 'userData/uploads/'; // folder for uploaded files
  220. $folder=Yii::app()->params['filepath'].Yii::app()->user->MId."/";
  221. $allowedExtensions = array( "jpg", "jpeg", "gif", "png" ); // array("jpg","jpeg","gif","exe","mov" and etc...
  222. $sizeLimit = 10*1024*1024; // maximum file size in bytes
  223. $uploader = new qqFileUploader( $allowedExtensions, $sizeLimit );
  224. $result = $uploader->handleUpload( $folder, true );
  225. $result = htmlspecialchars( json_encode( $result ), ENT_NOQUOTES );
  226. echo $result; // it's array
  227. }
  228. public function UserModuleCache($userId , $MId)
  229. {
  230. $this->_checkAuth();
  231. // Get All Roles Assigned to a user
  232. $RolesData = TblSysAuthAssignment::model()->findAllByAttributes( array( 'userid' => $userId, 'MId' => $MId ) );
  233. if (count( $RolesData ) > 0)
  234. {
  235. foreach ( $RolesData as $x => $y )
  236. {
  237. // Get All Tasks Assigned against the Role
  238. $Sql = "Select * from tbl_sys_AuthItemChild Where parent = '" . $y->itemname . "' AND MId ='" . $MId . "' GROUP BY ModuleId";
  239. $TaskList = TblSysAuthItemChild::model()->findAllBySql( $Sql );
  240. foreach ( $TaskList as $key => $value )
  241. {
  242. $SubModule[] = $value->ModuleId;
  243. }
  244. }
  245. }
  246. // Generate SubModule Data
  247. if (count( $SubModule ) > 0)
  248. {
  249. foreach ( $SubModule as $x => $y )
  250. {
  251. $masterdata = TblSysMasterModules::model()->findByAttributes( array( 'ModuleId' => $y, 'MId' => $MId ) );
  252. $mdata = TblModules::model()->findByPk( $y );
  253. if (is_null( $masterdata ))
  254. {
  255. $modulename = $mdata->Module;
  256. } else
  257. {
  258. $modulename = $masterdata->Module;
  259. }
  260. $items[] = array( 'label' => $modulename, 'url' => array( '/' . $mdata->Link ), 'task' => $mdata->Task );
  261. $ParentModule[] = $mdata->Parent;
  262. }
  263. }
  264. if (! is_null( $items ))
  265. {
  266. $serialize = serialize( $items );
  267. $Model = TblSysUserCache::model()->findByAttributes( array( 'UserId' => $userId, 'CacheName' => 'SubMenu' ) );
  268. if (is_null( ($Model) ))
  269. {
  270. // Store the Data in Module Cache
  271. $Model = new TblSysUserCache();
  272. }
  273. // Storing the Data in ModuleCache Table
  274. $Model->Cache = $serialize;
  275. $Model->UserId = $userId;
  276. $Model->MId = $MId;
  277. $Model->CacheName = 'SubMenu';
  278. $Model->save();
  279. }
  280. // Get Main Module Against the Tasks
  281. $itemsTop = array();
  282. if (count( $ParentModule ) > 0)
  283. {
  284. foreach ( array_unique( $ParentModule ) as $key => $value )
  285. {
  286. $masterdata = TblSysMasterModules::model()->findByAttributes( array( 'ModuleId' => $value, 'MId' => $MId ) );
  287. $mdata = TblModules::model()->findByAttributes( array( 'ModuleId' => $value, 'Visible' => 'Yes' ) );
  288. if (is_null( $masterdata ))
  289. {
  290. $modulename = $mdata->Module;
  291. } else
  292. {
  293. $modulename = $masterdata->Module;
  294. }
  295. $itemsTop[] = array( 'label' => $modulename, 'url' => array( '//' . $mdata->Controller ), 'task' => $mdata->Task );
  296. }
  297. }
  298. if (! is_null( $itemsTop ))
  299. {
  300. $serial = serialize( $itemsTop );
  301. // Search if The Menu already avaialble
  302. $Model = TblSysUserCache::model()->findByAttributes( array( 'UserId' => $userId, 'CacheName' => 'TopMenu' ) );
  303. if (is_null( ($Model) ))
  304. {
  305. // Store the Data in Module Cache
  306. $Model = new TblSysUserCache();
  307. }
  308. // Storing the Data in ModuleCache Table
  309. $Model->Cache = $serial;
  310. $Model->UserId = $userId;
  311. $Model->MId = $MId;
  312. $Model->CacheName = 'TopMenu';
  313. $Model->save();
  314. }
  315. return true;
  316. }
  317. public function actionEditUser($id)
  318. {
  319. // Fetch Data from Accounts
  320. $this->_checkAuth();
  321. $model = TblSysUsers::model()->findByPk( $id );
  322. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'users-form')
  323. {
  324. echo CActiveForm::validate( $model );
  325. Yii::app()->end();
  326. }
  327. if (strlen( $_POST['btnsave'] ) > 0)
  328. {
  329. if (isset( $_POST['TblSysUsers'] ))
  330. {
  331. // if it is ajax validation request
  332. $model->attributes = $_POST['TblSysUsers'];
  333. $model->MId = Yii::app()->user->MId;
  334. $model->WeightageId = $_POST['TblSysUsers']['WeightageId'];
  335. // validate user input and redirect to the previous page if valid
  336. if ($model->save())
  337. {
  338. // Update TblAuth Assignment
  339. if (count( $_POST['groups'] ) > 0)
  340. {
  341. TblSysAuthAssignment::model()->deleteAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'userid' => $_POST['TblSysUsers']['Userid'] ) );
  342. foreach ( $_POST['groups'] as $key => $value )
  343. {
  344. $moduleaccess = new TblSysAuthAssignment();
  345. $moduleaccess->itemname = $value;
  346. $moduleaccess->MId = Yii::app()->user->MId;
  347. $moduleaccess->userid = $model->Userid;
  348. $moduleaccess->save();
  349. }
  350. // Update User Menu Cache
  351. //$this->UserModuleCache( $model->Userid, Yii::app()->user->MId );
  352. }
  353. Yii::app()->session['notice'] = Yii::t( 'translate', 'User Updated' );
  354. Yii::app()->session['ntype'] = 'success';
  355. $this->redirect( "/admin/listUser" );
  356. } else
  357. {
  358. $msg = "<h1>Error</h1>";
  359. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  360. $msg .= "<ul>";
  361. foreach ( $model->errors as $attribute => $attr_errors )
  362. {
  363. $msg .= "<li>Attribute: $attribute</li>";
  364. $msg .= "<ul>";
  365. foreach ( $attr_errors as $attr_error )
  366. $msg .= "<li>$attr_error</li>";
  367. $msg .= "</ul>";
  368. }
  369. $msg .= "</ul>";
  370. $this->_sendResponse( 500, $msg );
  371. }
  372. }
  373. }
  374. $groupdata = TblSysAuthItem::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'type' => '2' ) );
  375. foreach ( $groupdata as $key => $value )
  376. {
  377. $group[$value['name']] = $value['name'];
  378. }
  379. $GroupList = TblSysAuthAssignment::model()->findAllByAttributes( array( 'MId' => Yii::app()->user->MId, 'userid' => $id ) );
  380. foreach ( $GroupList as $key => $value )
  381. {
  382. $AssignGroup[] = $value['itemname'];
  383. }
  384. echo $this->renderpartial( 'application.views.admin.modals._editUser', array( "model" => $model, "group" => $group, "groups" => $AssignGroup ), true, true );
  385. exit();
  386. }
  387. public function actionListGroups( )
  388. {
  389. $this->_checkAuth();
  390. $model = new TblSysAuthItem();
  391. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'groups-form')
  392. {
  393. echo CActiveForm::validate( $model );
  394. Yii::app()->end();
  395. }
  396. if (strlen( $_POST['btnsave'] ) > 0)
  397. {
  398. if (isset( $_POST['TblSysAuthItem'] ))
  399. {
  400. // if it is ajax validation request
  401. $model = new TblSysAuthItem();
  402. $model->attributes = $_POST['TblSysAuthItem'];
  403. $model->type = "2";
  404. $model->MId = Yii::app()->user->MId;
  405. // validate user input and redirect to the previous page if valid
  406. if ($model->save())
  407. {
  408. Yii::app()->session['notice'] = Yii::t( 'translate', 'Group Created' );
  409. Yii::app()->session['ntype'] = 'success';
  410. $this->redirect( "/admin/acl" );
  411. } else
  412. {
  413. $msg = "<h1>Error</h1>";
  414. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  415. $msg .= "<ul>";
  416. foreach ( $model->errors as $attribute => $attr_errors )
  417. {
  418. $msg .= "<li>Attribute: $attribute</li>";
  419. $msg .= "<ul>";
  420. foreach ( $attr_errors as $attr_error )
  421. $msg .= "<li>$attr_error</li>";
  422. $msg .= "</ul>";
  423. }
  424. $msg .= "</ul>";
  425. $this->_sendResponse( 500, $msg );
  426. }
  427. }
  428. }
  429. $criteria = new CDbCriteria();
  430. $criteria->select = " LEFT( name, 1 ) AS groupname";
  431. $criteria->condition = "type=2 and IsDelete=0 and MId = '" . Yii::app()->user->MId . "'";
  432. $criteria->order = "groupname ASC";
  433. $criteria->group = "groupname";
  434. $total = TblSysAuthItem::model()->count( $criteria );
  435. $pages = new CPagination( $total );
  436. $pages->pageSize = 5;
  437. $pages->applyLimit( $criteria );
  438. $groupmodel = TblSysAuthItem::model()->findAll( $criteria );
  439. $alphacriteria = new CDbCriteria();
  440. $alphacriteria->select = " LEFT( `name`, 1 ) AS `groupname`";
  441. $alphacriteria->condition = "IsDelete=0 and type=2 and MId='" . Yii::app()->user->MId . "'";
  442. $alphacriteria->group = "`groupname`";
  443. $alphacriteria->order = "`groupname` ASC";
  444. $alphasort = TblSysAuthItem::model()->findAll( $alphacriteria );
  445. $this->render( 'listGroups', array( "groupmodel" => $groupmodel, "model" => $model, "pages" => $pages, "alphasort" => $alphasort ) );
  446. }
  447. public function actionEditGroup($id)
  448. {
  449. // Fetch Data from Accounts
  450. $this->_checkAuth();
  451. $model = TblSysAuthItem::model()->findByPk( $id );
  452. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'groups-form')
  453. {
  454. echo CActiveForm::validate( $model );
  455. Yii::app()->end();
  456. }
  457. if (strlen( $_POST['btnsave'] ) > 0)
  458. {
  459. if (isset( $_POST['TblSysAuthItem'] ))
  460. {
  461. // if it is ajax validation request
  462. $model->name = $_POST['TblSysAuthItem']['name'];
  463. $model->description = $_POST['TblSysAuthItem']['description'];
  464. $model->type = 2;
  465. $model->MId = Yii::app()->user->MId;
  466. // validate user input and redirect to the previous page if valid
  467. if ($model->save())
  468. {
  469. Yii::app()->session['notice'] = Yii::t( 'translate', 'Group Updated' );
  470. Yii::app()->session['ntype'] = 'success';
  471. $this->redirect( "/admin/listGroups" );
  472. } else
  473. {
  474. $msg = "<h1>Error</h1>";
  475. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  476. $msg .= "<ul>";
  477. foreach ( $model->errors as $attribute => $attr_errors )
  478. {
  479. $msg .= "<li>Attribute: $attribute</li>";
  480. $msg .= "<ul>";
  481. foreach ( $attr_errors as $attr_error )
  482. $msg .= "<li>$attr_error</li>";
  483. $msg .= "</ul>";
  484. }
  485. $msg .= "</ul>";
  486. $this->_sendResponse( 500, $msg );
  487. }
  488. }
  489. }
  490. echo $this->renderpartial( 'application.views.admin.modals._editGroup', array( "model" => $model ), true, true );
  491. exit();
  492. }
  493. public function actionDeleteUser($id)
  494. {
  495. $this->_checkAuth();
  496. $delete = BWCFunctions::deleteRecordsByPk( 'TblSysUsers', $id, 'Name' );
  497. if ($delete)
  498. {
  499. $array = array( "success" => true );
  500. echo json_encode( $array );
  501. } else
  502. {
  503. $array = array( "success" => false );
  504. echo json_encode( $array );
  505. }
  506. }
  507. public function actionDeleteGroup($id)
  508. {
  509. $this->_checkAuth();
  510. $delete = BWCFunctions::deleteRecordsByPk( 'TblSysAuthItem', $id, "name" );
  511. if ($delete)
  512. {
  513. $array = array( "success" => true );
  514. echo json_encode( $array );
  515. } else
  516. {
  517. $array = array( "success" => false );
  518. echo json_encode( $array );
  519. }
  520. }
  521. public function actionAcl( )
  522. {
  523. $this->_checkAuth();
  524. if (count( $_POST['groupname'] ) > 0)
  525. {
  526. foreach ( $_POST['configoption'] as $key => $valgroup )
  527. {
  528. TblSysAuthItemChild::model()->deleteAllByAttributes( array( 'parent' => $key, 'MId' => Yii::app()->user->MId ) );
  529. foreach ( $valgroup as $keygrp => $val )
  530. {
  531. // Add to tbl_sys_AuthItemChild
  532. if ($val == "Yes")
  533. {
  534. // Get ModuleId
  535. $Module = TblModuleTask::model()->findByAttributes( array( 'Task' => $keygrp ) );
  536. $child = new TblSysAuthItemChild();
  537. $child->parent = $key;
  538. $child->child = $keygrp;
  539. $child->ModuleId = $Module->ModuleId;
  540. $child->MId = Yii::app()->user->MId;
  541. $child->save();
  542. //Check if task listed in tbl_sys_AuthItem Table
  543. $AuthItem = TblSysAuthItem::model()->findByAttributes(array('name'=>$keygrp, 'MId' => Yii::app()->user->MId));
  544. if(is_null($AuthItem))
  545. {
  546. $AuthItem = new TblSysAuthItem();
  547. $AuthItem->name = $keygrp;
  548. $AuthItem->MId = Yii::app()->user->MId;
  549. $AuthItem->type = 0;
  550. $AuthItem->save();
  551. }
  552. }
  553. }
  554. }
  555. }
  556. $dataProvider = new CActiveDataProvider( 'TblSysAuthItem', array( 'criteria' => array( 'condition' => 'type=2 and IsDelete=0 and MId = ' . Yii::app()->user->MId ) ) );
  557. $this->render( "acl", array( "model" => $model, "dataProvider" => $dataProvider ) );
  558. }
  559. public function actionCustomization( )
  560. {
  561. $model = TblMaster::model()->findByPk( Yii::app()->user->MId );
  562. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'frm-add-master')
  563. {
  564. echo CActiveForm::validate( $model );
  565. Yii::app()->end();
  566. }
  567. if (isset( $_POST['TblMaster'] ))
  568. {
  569. $model = TblMaster::model()->findByPk( Yii::app()->user->MId );
  570. $model->Company = $_POST['TblMaster']['Company'];
  571. $model->ContactNumber = $_POST['TblMaster']['ContactNumber'];
  572. $model->Background = $_POST['TblMaster']['Background'];
  573. $model->ZoomLevel = $_POST['TblMaster']['ZoomLevel'];
  574. if($_POST['TblMaster']['FrontendLogo']){
  575. $model->FrontendLogo = $_POST['TblMaster']['FrontendLogo'];
  576. }
  577. $file = CUploadedFile::getInstance( $model, 'FrontendLogo' );
  578. if (! is_null( $file ))
  579. {
  580. $model->FrontendLogo = CUploadedFile::getInstance( $model, 'FrontendLogo' );
  581. $filename = $model->FrontendLogo->getName();
  582. }
  583. if ($model->update())
  584. {
  585. if (! is_null( $file ))
  586. {
  587. $filename = $model->FrontendLogo->getName();
  588. $path = Yii::app()->params['documentPath'] . "uploads/" . $filename;
  589. $model->FrontendLogo->saveAs( $path );
  590. }
  591. $Master = TblMaster::model()->findByPk( $record->MId );
  592. if (strlen( $filename ) > 0)
  593. {
  594. Yii::app()->user->Logo = $filename;
  595. }
  596. Yii::app()->session['notice'] = Yii::t( 'translate', 'Customization Updated' );
  597. Yii::app()->session['ntype'] = 'success';
  598. $this->redirect( "/admin/customization" );
  599. }
  600. }
  601. $this->render( "customization", array( "model" => $model ) );
  602. }
  603. public function actionListDepartments( )
  604. {
  605. $this->_checkAuth();
  606. $model = new TblDepartments();
  607. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'department-form')
  608. {
  609. echo CActiveForm::validate( $model );
  610. Yii::app()->end();
  611. }
  612. if (strlen( $_POST['btnsave'] ) > 0)
  613. {
  614. if (isset( $_POST['TblDepartments'] ))
  615. {
  616. // if it is ajax validation request
  617. $model = new TblDepartments();
  618. $model->attributes = $_POST['TblDepartments'];
  619. $model->MId = Yii::app()->user->MId;
  620. // validate user input and redirect to the previous page if valid
  621. if ($model->save())
  622. {
  623. Yii::app()->session['notice'] = Yii::t( 'translate', 'Department Created' );
  624. Yii::app()->session['ntype'] = 'success';
  625. $this->redirect( "/admin/listDepartments" );
  626. } else
  627. {
  628. $msg = "<h1>Error</h1>";
  629. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  630. $msg .= "<ul>";
  631. foreach ( $model->errors as $attribute => $attr_errors )
  632. {
  633. $msg .= "<li>Attribute: $attribute</li>";
  634. $msg .= "<ul>";
  635. foreach ( $attr_errors as $attr_error )
  636. $msg .= "<li>$attr_error</li>";
  637. $msg .= "</ul>";
  638. }
  639. $msg .= "</ul>";
  640. $this->_sendResponse( 500, $msg );
  641. }
  642. }
  643. }
  644. $criteria = new CDbCriteria();
  645. $criteria->select = " LEFT( Department, 1 ) AS Name";
  646. $criteria->condition = "IsDelete=0 and MId = '" . Yii::app()->user->MId . "'";
  647. $criteria->order = "Name ASC";
  648. $criteria->group = "Name";
  649. $total = TblDepartments::model()->count( $criteria );
  650. $pages = new CPagination( $total );
  651. $pages->pageSize = 5;
  652. $pages->applyLimit( $criteria );
  653. $departmodel = TblDepartments::model()->findAll( $criteria );
  654. $alphacriteria = new CDbCriteria();
  655. $alphacriteria->select = " LEFT(Department, 1 ) AS Name";
  656. $alphacriteria->condition = "IsDelete=0 and MId = '" . Yii::app()->user->MId . "'";
  657. $alphacriteria->group = "Name";
  658. $alphacriteria->order = "Name ASC";
  659. $alphasort = TblDepartments::model()->findAll( $alphacriteria );
  660. $this->render( 'listDepartments', array( "model" => $model, "departmodel" => $departmodel, 'group' => $group, "pages" => $pages, "alphasort" => $alphasort ) );
  661. }
  662. public function actionEditDepartment($id)
  663. {
  664. $this->_checkAuth();
  665. $model = TblDepartments::model()->findByPk( $id );
  666. if (isset( $_POST['ajax'] ) && $_POST['ajax'] === 'department-form')
  667. {
  668. echo CActiveForm::validate( $model );
  669. Yii::app()->end();
  670. }
  671. if (strlen( $_POST['btnsave'] ) > 0)
  672. {
  673. if (isset( $_POST['TblDepartments'] ))
  674. {
  675. // if it is ajax validation request
  676. $model->attributes = $_POST['TblDepartments'];
  677. $model->MId = Yii::app()->user->MId;
  678. // validate user input and redirect to the previous page if valid
  679. if ($model->save())
  680. {
  681. Yii::app()->session['notice'] = Yii::t( 'translate', 'Department Updated' );
  682. Yii::app()->session['ntype'] = 'success';
  683. $this->redirect( "/admin/listDepartments" );
  684. } else
  685. {
  686. $msg = "<h1>Error</h1>";
  687. $msg .= sprintf( "Couldn't create model <b>%s</b>", $_GET['model'] );
  688. $msg .= "<ul>";
  689. foreach ( $model->errors as $attribute => $attr_errors )
  690. {
  691. $msg .= "<li>Attribute: $attribute</li>";
  692. $msg .= "<ul>";
  693. foreach ( $attr_errors as $attr_error )
  694. $msg .= "<li>$attr_error</li>";
  695. $msg .= "</ul>";
  696. }
  697. $msg .= "</ul>";
  698. $this->_sendResponse( 500, $msg );
  699. }
  700. }
  701. }
  702. echo $this->renderpartial( 'application.views.admin.modals._editDepartment', array( "model" => $model ), true, true );
  703. exit();
  704. }
  705. public function actionDeleteDepartment($id)
  706. {
  707. $this->_checkAuth();
  708. $delete = BWCFunctions::deleteRecordsByPk( 'TblDepartments', $id, 'Department' );
  709. if ($delete)
  710. {
  711. $array = array( "success" => true );
  712. echo json_encode( $array );
  713. } else
  714. {
  715. $array = array( "success" => false );
  716. echo json_encode( $array );
  717. }
  718. }
  719. }
  720. ?>