コード例 #1
0
ファイル: role.php プロジェクト: abdul-baten/hbcms
 public function action_add()
 {
     $this->template->title = 'Add Role';
     //print_r($data['roles']);
     $data = array();
     if ($_POST) {
         $role = new Model_Role();
         $post = $role->validate_create($_POST);
         if ($post->check()) {
             $values = $post->as_array();
             unset($post);
             $role->name = $values['name'];
             $role->description = $values['description'];
             $role->save();
             Request::instance()->redirect('role/index');
         } else {
             #Get errors for display in view
             $data['errors'] = $post->errors('racl/role/add', TRUE);
             #Repopulate $_POST data
             $_POST = $post->as_array();
         }
     }
     //
     $this->template->content = View::factory('racl/role/add', $data);
 }
コード例 #2
0
ファイル: role.php プロジェクト: nick-catanchin-ie/common
 /**
  * CRUD controller: UPDATE
  */
 public function action_update()
 {
     $id_role = $this->request->param('id');
     //we do not allow modify the admin
     if ($id_role == Model_Role::ROLE_ADMIN) {
         Alert::set(Alert::WARNING, __('Admin Role can not be modified!'));
         $this->redirect(Route::url('oc-panel', array('controller' => 'role')));
     }
     $this->template->title = __('Update') . ' ' . __($this->_orm_model) . ' ' . $id_role;
     $role = new Model_Role($id_role);
     if ($this->request->post() and $role->loaded()) {
         //delete all the access
         DB::delete('access')->where('id_role', '=', $role->id_role)->execute();
         //set all the access where post = on
         foreach ($_POST as $key => $value) {
             if ($value == 'on') {
                 DB::insert('access', array('id_role', 'access'))->values(array($role->id_role, str_replace('|', '.', $key)))->execute();
             }
         }
         //saving the role params
         $role->name = core::post('name');
         $role->description = core::post('description');
         $role->save();
         Alert::set(Alert::SUCCESS, __('Item updated'));
         $this->redirect(Route::get($this->_route_name)->uri(array('controller' => Request::current()->controller())));
     }
     //getting controllers actions
     $controllers = Model_Access::list_controllers();
     //get all the access this user has
     $query = DB::select('access')->from('access')->where('id_role', '=', $id_role)->execute();
     $access_in_use = array_keys($query->as_array('access'));
     // d(in_array('access_index',$access_in_use));
     //d($access_in_use);
     return $this->render('oc-panel/pages/role/update', array('role' => $role, 'controllers' => $controllers, 'access_in_use' => $access_in_use));
 }
コード例 #3
0
ファイル: roles.php プロジェクト: anqh/core
 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     // Load role
     $role_id = (int) $this->request->param('id', 0);
     if ($role_id) {
         $role = Model_Role::factory($role_id);
         if (!$role->loaded()) {
             throw new Model_Exception($role, $role_id);
         }
         Permission::required($role, Model_Role::PERMISSION_UPDATE, self::$user);
     } else {
         $role = Model_Role::factory();
         Permission::required($role, Model_Role::PERMISSION_CREATE, self::$user);
     }
     // Handle post
     $errors = array();
     if ($_POST) {
         $role->name = Arr::get($_POST, 'name');
         $role->description = Arr::get($_POST, 'description');
         try {
             $role->save();
             $this->request->redirect(Route::url('roles'));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Set title
     $this->view = View_Page::factory(__('Role') . ($role->name ? ': ' . $role->name : ''));
     // Set actions
     if ($role->loaded() && Permission::has($role, Model_Role::PERMISSION_DELETE, self::$user)) {
         $this->page_actions[] = array('link' => Route::model($role, 'delete') . '?token=' . Security::csrf(), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete role'), 'class' => 'btn btn-danger role-delete');
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_role($role, $errors));
 }
コード例 #4
0
 public function cRoleDel()
 {
     $this->_modelRole = $this->getGlobal('model/Role', 'Model_Role');
     if ($this->_modelRole->delete($this->getR('key'))) {
         $this->success('删除角色成功');
     } else {
         $this->error('删除角色失败');
     }
 }
コード例 #5
0
ファイル: batch.php プロジェクト: hemsinfotech/kodelearn
 public static function get_users_count($batch, $role_name = null)
 {
     $batch = $batch instanceof Model_Batch ? $batch : ORM::factory('batch', (int) $batch);
     if ($role_name) {
         $role = Model_Role::from_name($role_name);
         $users = $batch->users->join('roles_users', 'INNER')->on('users.id', ' = ', 'roles_users.user_id')->where('roles_users.role_id', ' = ', $role->id)->count_all();
     } else {
         $users = $batch->users->count_all();
     }
     return $users;
 }
コード例 #6
0
 /**
  * 编辑用户
  */
 public function cEdit()
 {
     $this->_modelUser = $this->getGlobal('model/User', 'Model_User');
     if ($this->isPost()) {
         $postArr = array('id' => intval($this->getR('id')), 'vuser' => $this->getR('vuser'), 'pwd' => $this->getR('pwd'), 'pwd1' => $this->getR('pwd1'), 'role' => $this->getR('role'), 'login_count' => RegistryRequest::getInstance()->absInt('login_count'));
         $info = $this->_modelUser->edit($postArr);
         if ($info['status'] == 1) {
             $this->success($info['info'], $info['url']);
         } else {
             $this->error($info['info'], $info['url']);
         }
     } else {
         $this->_modelRole = $this->getGlobal('model/Role', 'Model_Role');
         $roles = $this->_modelRole->getAll();
         $this->assign('roleList', $roles);
         $dataList = $this->_modelUser->findById($this->getR('id'));
         $dataList['role'] = $dataList['role'] ? explode(',', $dataList['role']) : array();
         $this->assign('dataList', $dataList);
         $this->display(VIEW_PAGE);
     }
 }
コード例 #7
0
ファイル: RoleBiz.php プロジェクト: emilymwang8/ibug
 public function get_user_role($user_id)
 {
     if ($user_id == 0) {
         return "";
     }
     $user_role_array = Model_UserRole::data_access()->filter(Model_UserRole::UserId, $user_id)->find();
     $user_role = $user_role_array[0];
     $role_id = $user_role->role_id;
     $role = Model_Role::data_access()->find_by_pk($role_id);
     $role_name = $role->name;
     return $role_name;
 }
コード例 #8
0
ファイル: UserRoleBiz.php プロジェクト: emilymwang8/ibug
 public function change_role($user_id, $new_role)
 {
     $dao = Model_Role::data_access();
     $role = $dao->filter(Model_Role::NAME, $new_role)->find();
     $role_id = $role[0]->id;
     $dao = Model_UserRole::data_access();
     $user_role_array = $dao->filter(Model_UserRole::UserId, $user_id)->find();
     $user_role = $user_role_array[0];
     $user_role->role_id = $role_id;
     $success = $user_role->save();
     return $success;
 }
コード例 #9
0
ファイル: Role.php プロジェクト: pancke/yyaf
 /**
  * 增加角色
  * @return NULL|boolean
  */
 public function addAction()
 {
     if ($this->isPost()) {
         $aRole = $this->_checkData();
         if (empty($aRole)) {
             return null;
         }
         if (Model_Role::addData($aRole) > 0) {
             return $this->showMsg('角色增加成功!', true);
         } else {
             return $this->showMsg('角色增加失败!', false);
         }
     } else {
         $this->assign('aPermissionList', Model_Permission::getAllPermissions());
         $this->assign('aMenuList', Model_Menu::getMenus());
     }
 }
コード例 #10
0
ファイル: Permission.php プロジェクト: pancke/yyaf
 {
     $aUser = Model_Admin::getDetail($iAdminID);
     if ($aUser['sRoleID'] === '-1') {
         return -1;
     }
     $aRoleList = Model_Role::getPKIDList($aUser['sRoleID']);
     $aModuleID = array();
     foreach ($aRoleList as $aRole) {
         if (!empty($aRole['sModule'])) {
             $aModuleID = array_merge($aModuleID, explode(',', $aRole['sModule']));
         }
     }
     return array_flip($aModuleID);
 }
 /**
  * 取得用户所有访问权限
  * 
  * @param array $aUser            
  * @return array
  */
 public static function getUserPermissions($iAdminID)
コード例 #11
0
ファイル: roles.php プロジェクト: anqh/core
    /**
     * Render view.
     *
     * @return  string
     */
    public function content()
    {
        ob_start();
        ?>

<ul>
		<?php 
        foreach (Model_Role::factory()->find_all() as $role) {
            ?>
		<li><?php 
            echo HTML::anchor(Route::model($role, 'edit', false), $role->name), ' - ', HTML::chars($role->description);
            ?>
</li>
		<?php 
        }
        ?>
</ul>

<?php 
        return ob_get_clean();
    }
コード例 #12
0
ファイル: auth.php プロジェクト: rrsc/beansbooks
 /**
  * Returns the access and information tied to a role.
  * @param  Model_Role $role
  * @return stdClass		stdClass of all properties for this role.
  * @throws Exception If Role object is not valid.
  */
 public function _return_role_element($role)
 {
     $return_object = new stdClass();
     if (!$role->loaded() or get_class($role) != "Model_Role") {
         throw new Exception("Invalid Role.");
     }
     $return_object->id = $role->id;
     $return_object->name = $role->name;
     $return_object->code = $role->code;
     $return_object->description = $role->description;
     $return_object->auth_expiration_length = $role->auth_expiration_length;
     $return_object->customer_read = $role->customer_read ? TRUE : FALSE;
     $return_object->customer_write = $role->customer_write ? TRUE : FALSE;
     $return_object->customer_sale_read = $role->customer_sale_read ? TRUE : FALSE;
     $return_object->customer_sale_write = $role->customer_sale_write ? TRUE : FALSE;
     $return_object->customer_payment_read = $role->customer_payment_read ? TRUE : FALSE;
     $return_object->customer_payment_write = $role->customer_payment_write ? TRUE : FALSE;
     $return_object->vendor_read = $role->vendor_read ? TRUE : FALSE;
     $return_object->vendor_write = $role->vendor_write ? TRUE : FALSE;
     $return_object->vendor_expense_read = $role->vendor_expense_read ? TRUE : FALSE;
     $return_object->vendor_expense_write = $role->vendor_expense_write ? TRUE : FALSE;
     $return_object->vendor_purchase_read = $role->vendor_purchase_read ? TRUE : FALSE;
     $return_object->vendor_purchase_write = $role->vendor_purchase_write ? TRUE : FALSE;
     $return_object->vendor_payment_read = $role->vendor_payment_read ? TRUE : FALSE;
     $return_object->vendor_payment_write = $role->vendor_payment_write ? TRUE : FALSE;
     $return_object->account_read = $role->account_read ? TRUE : FALSE;
     $return_object->account_write = $role->account_write ? TRUE : FALSE;
     $return_object->account_transaction_read = $role->account_transaction_read ? TRUE : FALSE;
     $return_object->account_transaction_write = $role->account_transaction_write ? TRUE : FALSE;
     $return_object->account_reconcile = $role->account_reconcile ? TRUE : FALSE;
     $return_object->books = $role->books ? TRUE : FALSE;
     $return_object->reports = $role->reports ? TRUE : FALSE;
     $return_object->setup = $role->setup ? TRUE : FALSE;
     return $return_object;
 }
コード例 #13
0
ファイル: warden.php プロジェクト: nsbasicus/warden
 private function _create_default_role()
 {
     \Cli::beep(1);
     // get attention
     $create_role = \Cli::prompt("\nCreate a default user role?", array('y', 'n'));
     if ($create_role === 'y') {
         $role_name = \Cli::prompt("\nPlease enter the role name");
         try {
             $new = \Model_Role::forge(array('name' => $role_name, 'description' => 'Default login role.'))->save();
             \Config::set('warden.default_role', $role_name);
             \Cli::write(\Cli::color("\nRole id  : {$new}", 'blue'));
             \Cli::write(\Cli::color("Role name: {$role_name}", 'blue'));
         } catch (\Exception $e) {
             \Cli::error("\n:( Failed to create default role because: {$e->getMessage()}");
         }
     }
 }
コード例 #14
0
ファイル: UsernewBiz.php プロジェクト: emilymwang8/ibug
 public function get_admins()
 {
     $dao = Model_Role::data_access();
     $admin = $dao->filter(Model_Role::NAME, 'admin')->find();
     $admin_id = $admin[0]->id;
     $dao = Model_UserRole::data_access();
     $user_role = $dao->filter(Model_UserRole::RoleId, $admin_id)->find();
     $user = array();
     foreach ($user_role as $key => $value) {
         $dao = Model_User::data_access();
         $tmp = $dao->filter(Model_User::UserId, $value->user_id)->find();
         $user[$key] = $tmp[0];
     }
     return $user;
 }
コード例 #15
0
ファイル: admin_role.php プロジェクト: roni5/sela
 * This file was automatically generated By Code Smith 
 * Modifications will be overwritten when code smith is run
 *
 * PLEASE DO NOT MAKE MODIFICATIONS TO THIS FILE
 * Date Created 5/6/2012
 *
 */
/// <summary>
/// Implementations of slroles represent a Role
///
/// </summary>
chdir("..");
/* TODO: Add code here */
require 'config/globalconfig.php';
include_once 'class/model_role.php';
$objRole = new Model_Role($objConnection);
if ($_pgR["act"] == model_Role::ACT_ADD) {
    if (global_common::isCLogin()) {
        //get user info
        //$c_userInfo = $_SESSION[consts::SES_C_USERINFO];
        //if ($objMenu->getMenuByName($_pgR['name'])) {
        //	echo global_common::convertToXML($arrHeader, array("rs",'info'), array(0,global_common::STRING_NAME_EXIST), array(0,1));
        //	return;
        //}
        $roleID = $_pgR['RoleID'];
        $roleID = global_editor::rteSafe(html_entity_decode($roleID, ENT_COMPAT, 'UTF-8'));
        $roleName = $_pgR['RoleName'];
        $roleName = global_editor::rteSafe(html_entity_decode($roleName, ENT_COMPAT, 'UTF-8'));
        $status = $_pgR['Status'];
        $status = global_editor::rteSafe(html_entity_decode($status, ENT_COMPAT, 'UTF-8'));
        //$strName = $_pgR['name'];
コード例 #16
0
ファイル: Account.php プロジェクト: maxwroc/PHP
 public function userAction($iId = null)
 {
     $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit');
     // sprawdzamy czy user jest adminem
     if ($this->sRole !== 'admin') {
         $aData['info'] = $this->getLang('access_denied');
         $this->mTemplate->content = View::factory('account/item_edit', $aData)->render();
         return;
     }
     if (isset($iId) and $iId !== 0 and !isset($_POST['submit'])) {
         // edycja usera
         $bDelete = func_get_arg(0) == 'delete';
         if ($bDelete) {
             $iId = func_get_arg(1);
         }
         $iId = (int) $iId;
         $oUser = new Model_User($iId);
         $aUser = $oUser->getRow();
         if ($iId and !empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) {
             if ($bDelete) {
                 // usuwanie uzytkownika
                 if (func_num_args() == 4 and $this->oAuth->isValidToken(func_get_arg(2))) {
                     if ($oUser->delete()) {
                         $aMeta = $this->mTemplate->aMeta;
                         $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                         $this->mTemplate->aMeta = $aMeta;
                         $aData['info'] = $this->getLang('delele_user_successfull');
                     } else {
                         $aData['info'] = $this->getLang('delele_user_failed');
                     }
                 } else {
                     // potwierdzenie usuniecia
                     $aData = array('sQuestion' => $this->getLang('delele_user_question', $aUser['name']), 'sTextYes' => $this->getLang('Catering.ok'), 'sLinkYes' => '/account/user/delete/' . $iId . '/' . $this->oAuth->getSecurityToken() . '/', 'sTextNo' => $this->getLang('Catering.cancel'), 'sLinkNo' => '/account/user/' . $iId . '/');
                 }
                 $this->mTemplate->sSectionTitle = $this->getLang('section_title_userdelete');
             } else {
                 // edycja danych
                 $aOptions = array();
                 $aLayoutList = array();
                 $oRole = new Model_Role();
                 $aRoles = $oRole->getAll();
                 foreach ($aRoles as $aRole) {
                     $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']);
                 }
                 // pobieramy dostepne layouty
                 $oLayout = new Model_Layout();
                 $aLayouts = $oLayout->getAll();
                 foreach ($aLayouts as $aLayout) {
                     $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']);
                 }
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => $aUser['fname']);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => $aUser['name']);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => $aUser['email']);
                 $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => '');
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('registered'), 'name' => 'since', 'value' => $aUser['since'], 'disabled' => true);
                 $aInputs[] = array('type' => 'text', 'label' => $this->getLang('last_login'), 'name' => 'last_login', 'value' => $aUser['last_login'], 'disabled' => true);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => $aUser['layout_id'], 'items' => $aLayoutList);
                 $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => $aUser['role_id'], 'items' => $aOptions);
                 $aInputs[] = array('type' => 'hidden', 'name' => 'user_id', 'value' => $aUser['user_id']);
                 $aData = array('bPrintForm' => true, 'aInputs' => $aInputs, 'sTextDelete' => $this->getLang('delete'), 'sLinkDelete' => '/account/user/delete/' . $aUser['user_id'] . '/');
                 $this->mTemplate->sSectionTitle = $this->getLang('section_title_useredit');
             }
         } else {
             $aData['info'] = $this->getLang('user_not_found');
         }
     } elseif (isset($_POST['submit'])) {
         // zapis usera
         $sFName = $this->post('fname');
         $sName = $this->post('name');
         $sPass = $this->post('pass');
         $sEmail = $this->post('email');
         $iRole = $this->post('role');
         $iLayout = $this->post('layout');
         $user_id = $this->post('user_id');
         $oValidator = new Module_Validator();
         $oValidator->field('first_name', $sFName)->rules('required');
         $oValidator->field('sure_name', $sName)->rules('required');
         $oValidator->field('email', $sEmail)->rules('required|email');
         $oValidator->field('layout', $iLayout)->rules('required|toint');
         $oValidator->field('role', $iRole)->rules('required|toint');
         $oValidator->field('user_id', $user_id)->rules('toint');
         if ($user_id == 0) {
             $oValidator->field($this->getLang('password'), $sPass)->rules('required|md5');
         } elseif (strlen($sPass)) {
             $oValidator->field($this->getLang('password'), $sPass)->rules('md5');
         }
         if ($oValidator->validate()) {
             if ($user_id == 0) {
                 //zapis nowego usera
                 $oUser = new Model_User();
                 $oUser->fname = $sFName;
                 $oUser->name = $sName;
                 $oUser->email = $sEmail;
                 $oUser->password = $sPass;
                 $oUser->layout_id = $iLayout;
                 $oUser->role_id = $iRole;
                 $oUser->account_id = $this->oCurrentUser->account_id;
                 if ($oUser->save()) {
                     $aMeta = $this->mTemplate->aMeta;
                     $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                     $this->mTemplate->aMeta = $aMeta;
                     $aData['info'] = $this->getLang('save_user_successfull');
                 } else {
                     $aData['info'] = $this->getLang('save_user_failed');
                 }
             } else {
                 // zapis edytowanego usera
                 $oUser = new Model_User($user_id);
                 $aUser = $oUser->getRow();
                 if (!empty($aUser) and $aUser['account_id'] == $this->oCurrentUser->account_id) {
                     $oUser->fname = $sFName;
                     $oUser->name = $sName;
                     $oUser->email = $sEmail;
                     $oUser->layout_id = $iLayout;
                     $oUser->role_id = $iRole;
                     if (!empty($sPass)) {
                         $oUser->password = $sPass;
                     }
                     if ($oUser->save()) {
                         $aMeta = $this->mTemplate->aMeta;
                         $aMeta[] = '<meta http-equiv="refresh" content="1;url=' . $this->mTemplate->anchor('/account/users/') . '" />';
                         $this->mTemplate->aMeta = $aMeta;
                         $aData['info'] = $this->getLang('save_user_successfull');
                     } else {
                         $aData['info'] = $this->getLang('save_user_failed');
                     }
                 }
             }
         } else {
             $aErrors = $oValidator->getError();
             foreach ($aErrors as $sField => $aError) {
                 $sMsg .= '<br />' . $this->getLang($aError['msg'], $this->getLang($sField));
             }
             $aData['info'] = $sMsg;
         }
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_save');
     } else {
         // akcja domyślna czyli dodawanie usera
         $aOptions = array();
         $aLayoutList = array();
         // pobieramy dostepne role
         $oRole = new Model_Role();
         $aRoles = $oRole->getAll();
         foreach ($aRoles as $aRole) {
             $aOptions[] = array('value' => $aRole['role_id'], 'name' => $aRole['name']);
         }
         // pobieramy dostepne layouty
         $oLayout = new Model_Layout();
         $aLayouts = $oLayout->getAll();
         foreach ($aLayouts as $aLayout) {
             $aLayoutList[] = array('value' => $aLayout['layout_id'], 'name' => $aLayout['name']);
         }
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('first_name'), 'name' => 'fname', 'value' => '');
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('sure_name'), 'name' => 'name', 'value' => '');
         $aInputs[] = array('type' => 'text', 'label' => $this->getLang('email'), 'name' => 'email', 'value' => '');
         $aInputs[] = array('type' => 'password', 'label' => $this->getLang('password'), 'name' => 'pass', 'value' => '');
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('layout'), 'name' => 'layout', 'value' => 2, 'items' => $aLayoutList);
         $aInputs[] = array('type' => 'select', 'label' => $this->getLang('role'), 'name' => 'role', 'value' => 3, 'items' => $aOptions);
         $aData = array('bPrintForm' => true, 'aInputs' => $aInputs);
         $this->mTemplate->sSectionTitle = $this->getLang('section_title_user_add');
     }
     $aData['submit'] = $this->getLang('Catering.save');
     $this->mTemplate->content = View::factory('/account/item_edit', $aData)->render();
 }
コード例 #17
0
ファイル: User.php プロジェクト: pancke/yyaf
 /**
  * 增加用户
  */
 public function addAction()
 {
     if ($this->_request->isPost()) {
         $aUser = $this->_checkData('add');
         if (empty($aUser)) {
             return null;
         }
         if (Model_Admin::getAdminByName($aUser['sAdminName'])) {
             return $this->showMsg('用户已经存在!', false);
         }
         if (Model_Admin::addData($aUser) > 0) {
             return $this->showMsg('用户增加成功!', true);
         } else {
             return $this->showMsg('用户增加失败!', false);
         }
     } else {
         $this->assign('aCity', Model_City::getPairCitys());
         $this->assign('aRole', Model_Role::getPairRoles());
     }
 }
コード例 #18
0
ファイル: user.php プロジェクト: anqh/anqh
 /**
  * Get roles.
  *
  * @return  array
  */
 public function roles()
 {
     if (!$this->_roles) {
         $this->_roles = Model_Role::find_by_user($this);
     }
     return $this->_roles;
 }
コード例 #19
0
ファイル: lecture.php プロジェクト: hemsinfotech/kodelearn
 private function form($action, $submitted = false, $saved_data = array())
 {
     $courses = ORM::factory('course')->find_all()->as_array('id', 'name');
     $users = array();
     foreach (Model_Role::get_users('teacher') as $user) {
         $users[$user->id] = $user->firstname . ' ' . $user->lastname;
     }
     $rooms = array();
     foreach (ORM::factory('room')->find_all() as $room) {
         $rooms[$room->id] = $room->room_number . ', ' . $room->room_name;
     }
     $form = new Stickyform($action, array(), $submitted ? $this->_errors : array());
     $form->default_data = array('name' => '', 'user_id' => '', 'course_id' => '', 'room_id' => '', 'once_date' => '', 'repeat_from' => '', 'repeat_to' => '', 'type' => 'once');
     $form->saved_data = $saved_data;
     $form->posted_data = $submitted ? Stickyform::ungroup_params($this->request->post()) : array();
     $form->append('Name', 'name', 'text');
     $form->append('Type', 'type', 'radio');
     $form->append('Date:', 'once_date', 'text', array('attributes' => array('class' => 'date', 'name' => 'once[date]')));
     $form->append('From:', 'repeat_from', 'text', array('attributes' => array('class' => 'date', 'name' => 'repeat[from]')));
     $form->append('To:', 'repeat_to', 'text', array('attributes' => array('class' => 'date', 'name' => 'repeat[to]')));
     $form->append('Lecturer', 'user_id', 'select', array('options' => $users));
     $form->append('Course', 'course_id', 'select', array('options' => $courses));
     $form->append('Room', 'room_id', 'select', array('options' => $rooms));
     $form->append('Save', 'save', 'submit', array('attributes' => array('class' => 'button')));
     $form->process();
     return $form;
 }
コード例 #20
0
ファイル: auth.php プロジェクト: hemsinfotech/kodelearn
 private function parent_register()
 {
     $user = ORM::factory('user');
     $config_settings = Config::instance()->load('config');
     $auto_login = true;
     $validator = $user->validator_parent_register($this->request->post());
     $validator->bind(':email', $this->request->post('email'));
     if ($validator->check()) {
         $values = array('firstname' => $this->request->post('firstname'), 'lastname' => $this->request->post('lastname'), 'email' => $this->request->post('email'), 'password' => Auth::instance()->hash($this->request->post('password')));
         $role = ORM::factory('role', $config_settings->default_role);
         $user_id = $this->create_user($values, $role);
         $user = ORM::factory('user', $user_id);
         //first check if child's account exists
         $child = ORM::factory('user')->where('email', '=', $this->request->post('email_child'))->find();
         if (!$child->id) {
             $child_password = rand(10000, 65000);
             $values = array('firstname' => $this->request->post('childname'), 'lastname' => $this->request->post('lastname'), 'email' => $this->request->post('email_child'), 'password' => Auth::instance()->hash($child_password), 'parent_user_id' => $user_id);
             $role = Model_Role::from_name('Student');
             $child_id = $this->create_user($values, $role);
             $child = ORM::factory('user', $child_id);
         }
         $child->parent_user_id = $user_id;
         $child->save();
         if ($config_settings->user_approval) {
             $auto_login = false;
         }
         $user->send_child_email();
         $user->send_user_email();
         if ($auto_login) {
             Auth::instance()->login($validator['email'], $validator['password']);
             Request::current()->redirect('home');
             exit;
         } else {
             Request::current()->redirect('auth/index/admin_aproval/1');
         }
         exit;
     } else {
         $this->_errors = $validator->errors('register');
     }
 }
コード例 #21
0
ファイル: master.php プロジェクト: CeusMedia/Hydra
$badges = array();
$infos = array($words['footer_info']['copyright'], sprintf($words['footer_info']['date'], date('d.m.Y')), sprintf($words['footer_info']['time'], date('H:i:s')));
if (!$config->get('app.production')) {
    $infos[] = sprintf($words['footer_info']['time_stopped'], $env->getClock()->stop(0, 2));
    if ($env->has('dbc') && $env->getDatabase()->numberStatements) {
        $infos[] = sprintf($words['footer_info']['requests'], $env->getDatabase()->numberStatements);
    }
}
$userId = (int) $session->get('userId');
$roleId = (int) $session->get('roleId');
if ($userId) {
    $modelUser = new Model_User($env);
    $infos[] = 'Benutzer: ' . $modelUser->get($userId, 'username') . ' <small>(' . $userId . ')</small>';
}
if ($roleId) {
    $modelRole = new Model_Role($env);
    $infos[] = 'Rolle: ' . $modelRole->get($userId, 'title') . ' <small>(' . $roleId . ')</small>';
}
$badges[] = '<a href="http://validator.w3.org/check?uri=referer"><img style="border: 0; width: 48px; height: 16px" src="http://www.w3.org/Icons/valid-xhtml10" alt="validate HTML (as XHTML 1.0 Strict)"/></a>';
$badges[] = '<a href="http://jigsaw.w3.org/css-validator/check/referer"><img style="border: 0; width: 48px; height: 16px" src="http://jigsaw.w3.org/css-validator/images/vcss" alt="validate CSS"/></a>';
$infos = '<span>' . join('</span><span>', $infos) . '</span>';
$badges = '<span>' . join('</span><span>', $badges) . '</span>';
$linkReset = '<a href="./?resetInstanceId">Instanz</a>';
$path = $env->getRequest()->get('__path');
$body = '
<script>
function selectInstanceId(id, forward){
	var url = "./admin/instance/select/"+id;
	if(forward)
		url += "?forward="+forward;
	document.location.href = url;
コード例 #22
0
ファイル: user.php プロジェクト: nsbasicus/warden
 /**
  * Adds default role to a new user if enabled in config
  *
  * @see \Warden\Model_User::_event_before_save()
  */
 private function _add_default_role()
 {
     // Make sure no roles exist already
     if (empty($this->roles) || !static::query()->related('roles')->get_one()) {
         // Check for default role
         if ($default_role = \Config::get('warden.default_role')) {
             $role = \Model_Role::find('first', array('where' => array('name' => $default_role)));
             if (!is_null($role)) {
                 $this->roles[] = $role;
             }
         }
     }
 }
コード例 #23
0
ファイル: course.php プロジェクト: hemsinfotech/kodelearn
 public static function get_users_count($course, $role_name = null)
 {
     $course = $course instanceof Model_Course ? $course : ORM::factory('course', (int) $course);
     if ($role_name) {
         $role = Model_Role::from_name($role_name);
         $users = $course->users->join('roles_users', 'INNER')->on('users.id', ' = ', 'roles_users.user_id')->where('roles_users.role_id', ' = ', $role->id)->count_all();
     } else {
         $users = $course->users->count_all();
     }
     return $users;
 }
コード例 #24
0
ファイル: Can.php プロジェクト: huiancg/kohana-huia-manager
 protected static function role_exists($name)
 {
     return (bool) Model_Role::factory('Role', array('name' => $name))->id;
 }
コード例 #25
0
ファイル: course.php プロジェクト: hemsinfotech/kodelearn
 public function action_edit()
 {
     $submitted = false;
     $id = $this->request->param('id');
     if (!$id) {
         Request::current()->redirect('course');
     }
     $course = ORM::factory('course', $id);
     if ($this->request->method() === 'POST' && $this->request->post()) {
         if (Arr::get($this->request->post(), 'save') !== null) {
             $submitted = true;
             $validator = $course->validator($this->request->post());
             $validator->bind(':course', $course);
             $validator->bind(':start_date', $this->request->post('start_date'));
             if ($validator->check()) {
                 $course->name = $this->request->post('name');
                 $course->description = $this->request->post('description');
                 $course->access_code = $this->request->post('access_code');
                 $course->start_date = $this->request->post('start_date');
                 $course->end_date = $this->request->post('end_date');
                 $course->save();
                 Session::instance()->set('success', 'Cources edited successfully.');
                 Model_Course::assign_users($course, $this->request->post('selected'));
                 Request::current()->redirect('course');
                 exit;
             } else {
                 $this->_errors = $validator->errors('course');
             }
         }
     }
     $saved_data = array('name' => $course->name, 'description' => $course->description, 'access_code' => $course->access_code, 'start_date' => $course->start_date, 'end_date' => $course->end_date);
     $form = $this->form('course/edit/id/' . $id, $submitted, $saved_data);
     $data = Model_Course::get_students($course);
     $cacheimage = CacheImage::instance();
     $user_ids = $data->as_array(NULL, 'id');
     $count = $course->users->count_all();
     $users = View::factory('course/assign')->bind('data', $data)->bind('count', $count)->bind('cacheimage', $cacheimage)->bind('user_ids', $user_ids);
     $teachers = Model_Role::get_users('teacher');
     $assigned_teachers = Model_Course::get_teachers($course)->as_array(null, 'id');
     $teachers_table = View::factory('course/teachers')->bind('teachers', $teachers)->bind('cacheimage', $cacheimage)->bind('assigned_teachers', $assigned_teachers);
     $batches = ORM::factory('batch')->find_all();
     $view = View::factory('course/form')->bind('form', $form)->bind('users', $users)->bind('batches', $batches)->bind('teachers_table', $teachers_table)->bind('course_id', $id);
     Breadcrumbs::add(array('Courses', Url::site('course')));
     Breadcrumbs::add(array($course->name, Url::site('course/edit/id/' . $id)));
     $this->content = $view;
 }