Exemplo n.º 1
0
 public function getRemoveRole($user_id, $role_id)
 {
     $userroles = UserRole::find(array('user_id', '=', $user_id), array('role_id', '=', $role_id));
     foreach ($userroles as $ur) {
         if ($ur->delete()) {
             $this->flash()->success('@string/user_role_remove_success');
         }
     }
     return $this->response()->redirect();
 }
Exemplo n.º 2
0
 public static function findByUserId($id)
 {
     $userroles = UserRole::find(array('where' => 'user_id = :user_id', 'values' => array(':user_id' => (int) $id)));
     if (count($userroles) <= 0) {
         return false;
     }
     $roles = array();
     foreach ($userroles as $role) {
         $roles[] = Role::findById($role->role_id);
     }
     return $roles;
 }
Exemplo n.º 3
0
 public function mail()
 {
     if (!(($id = OAInput::post('id')) && ($contact = Contact::find_by_id($id, array('select' => 'name, email, message'))))) {
         return false;
     }
     if (!(($admin_ids = array_unique(column_array(UserRole::find('all', array('select' => 'user_id', 'conditions' => array('name IN (?)', array('root', 'contact_manager')))), 'user_id'))) && ($admins = User::find('all', array('select' => 'name, email', 'conditions' => array('id IN (?)', $admin_ids)))))) {
         return false;
     }
     $this->load->library('OAMail');
     $email = $contact->email;
     $name = $contact->name;
     $message = $contact->message;
     $mail = OAMail::create()->setSubject('[系統通知] 官網有新的留言!')->setBody("<article style='font-size:15px;line-height:22px;color:rgb(85,85,85)'><p style='margin-bottom:0'>Hi 管理員,</p><section style='padding:5px 20px'><p>剛剛有一個訪客在您的「聯絡我們」留言囉,以下他所留下的聯絡資料:</p><table style='width:100%;border-collapse:collapse'><tbody><tr><th style='width:100px;text-align:right;padding:11px 5px 10px 0;border-bottom:1px dashed rgba(200,200,200,1)'>E-Mail:</th><td style='text-align:left;text-align:left;padding:11px 0 10px 5px;border-bottom:1px dashed rgba(200,200,200,1)'>" . $email . "</td></tr><tr><th style='width:100px;text-align:right;padding:11px 5px 10px 0;border-bottom:1px dashed rgba(200,200,200,1)'>稱 呼:</th><td style='text-align:left;text-align:left;padding:11px 0 10px 5px;border-bottom:1px dashed rgba(200,200,200,1)'>" . $name . "</td></tr><tr><th style='width:100px;text-align:right;padding:11px 5px 10px 0;border-bottom:1px dashed rgba(200,200,200,1)'>內容:</th><td style='text-align:left;text-align:left;padding:11px 0 10px 5px;border-bottom:1px dashed rgba(200,200,200,1)'>" . $message . "</td></tr></tbody></table><br/><p style='text-align:right'>如果需要詳細列表,可以置<a href='" . base_url('admin', 'contacts') . "' style='color:rgba(96,156,255,1);margin:0 2px'>管理後台</a>檢閱。</p></section></article>");
     foreach ($admins as $admin) {
         $mail->addTo($admin->email, $admin->name);
     }
     $mail->send();
     $mail = OAMail::create()->setSubject('[宙思設計] 留言成功通知!')->setBody("<article style='font-size:15px;line-height:22px;color:rgb(85, 85, 85)'><p style='margin-bottom:0'>Hi " . $name . ",</p><section style='padding:5px 20px'><p>您好,我們是<a href='http://www.zeusdesign.com.tw/' style='color:rgba(96, 156, 255, 1);margin:0 2px'>宙思設計</a>團隊,我們已經收到您的留言囉。</p><p>我們稍後會有專人主動與您聯絡或回信給您!</p><p>若是尚未得到回覆,您可以至<a href='https://www.facebook.com/ZeusDesignStudio/' style='color:rgba(96, 156, 255, 1);margin:0 2px'>宙思設計臉書粉絲專頁</a>留言,或來電(02-2941-6737)聯絡我們。</p><p style='text-align:right'>- <a href='http://www.zeusdesign.com.tw/' style='color:rgba(96, 156, 255, 1);margin:0 2px'>宙思設計</a>團隊感謝您。</p></section></article>")->addTo($email, $name);
     $mail->send();
 }
Exemplo n.º 4
0
 public function update()
 {
     if (!$this->has_post()) {
         return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。'));
     }
     $posts = OAInput::post();
     if ($msg = $this->_validation_posts($posts)) {
         return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => $msg, 'posts' => $posts));
     }
     if ($columns = array_intersect_key($posts, $this->user->table()->columns)) {
         foreach ($columns as $column => $value) {
             $this->user->{$column} = $value;
         }
     }
     $user = $this->user;
     $update = user::transaction(function () use($user) {
         return $user->save();
     });
     if (!$update) {
         return redirect_message(array('admin', $this->get_class(), $this->user->id, 'edit'), array('_flash_message' => '更新失敗!', 'posts' => $posts));
     }
     $ori_keys = column_array($user->roles, 'name');
     if (($del_keys = array_diff($ori_keys, $posts['roles'])) && ($roles = UserRole::find('all', array('select' => 'id', 'conditions' => array('user_id = ? AND name IN (?)', $user->id, $del_keys))))) {
         foreach ($roles as $role) {
             UserRole::transaction(function () use($role) {
                 return $role->destroy();
             });
         }
     }
     if ($add_keys = array_diff($posts['roles'], $ori_keys)) {
         foreach ($add_keys as $add_key) {
             UserRole::transaction(function () use($add_key, $user) {
                 return verifyCreateOrm(UserRole::create(Array_intersect_key(array('name' => $add_key, 'user_id' => $user->id), UserRole::table()->columns)));
             });
         }
     }
     return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '更新成功!'));
 }
Exemplo n.º 5
0
 /**
  * Template User Roles
  * If null user roles get all user roles and set it to all.
  * 
  * @param mixed $roles 
  * @todo Why is this checking a variable that isn't passed?
  */
 protected function _templateUserRoles($roles)
 {
     if ($template['Webpage']['user_roles'] === null) {
         App::uses('UserRole', 'Users.Model');
         $UserRole = new UserRole();
         $roles = serialize(Set::extract('/UserRole/id', $UserRole->find('all', array('fields' => array('UserRole.id')))));
     }
     return $roles;
 }
Exemplo n.º 6
0
 public static function GetByRoleId($roleId)
 {
     return UserRole::find('all', array('role_id' => $roleId));
 }
 public function role_destroy($id)
 {
     UserRole::find($id)->delete();
 }
 /**
  * @Route("/delete/{id}", methods={"POST"}, name="userroledelete")
  */
 public function deleteAction($id)
 {
     $userdata = explode('-', $id);
     $userid = $userdata[0];
     $roleid = $userdata[1];
     $entity = UserRole::find(array("conditions" => "userid = :userid: and roleid = :roleid:", "bind" => array('userid' => $userid, 'roleid' => $roleid)));
     if (!$entity->delete()) {
         foreach ($addres->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "UserRole", "action" => "show", "parameters" => array($id)));
     } else {
         $this->response->redirect(array('for' => 'userrolelist', 'userid' => $userid));
     }
 }
Exemplo n.º 9
0
 /**
  * Menu method
  * Create a new menu for a user specific case for menu creation during build
  * 
  */
 public function menu()
 {
     App::uses('UserRole', 'Users.Model');
     $UserRole = new UserRole();
     $userRoles = $UserRole->find('list');
     $text = __('%s Dashboard', Inflector::humanize($userRoles[$this->request->data['WebpageMenu']['user_role_id']]));
     $this->request->data['WebpageMenu']['name'] = $text;
     $this->request->data['WebpageMenu']['parent_id'] = null;
     $this->request->data['WebpageMenu']['item_text'] = $text;
     App::uses('WebpageMenu', 'Webpages.Model');
     $WebpageMenu = new WebpageMenu();
     $WebpageMenu->create();
     if ($WebpageMenu->save($this->request->data)) {
         $this->Session->setFlash(__('New flow started'));
         $this->redirect($this->referer());
     } else {
         $this->Session->setFlash(__('Save failure. Please, try again.'));
         $this->redirect($this->referer());
     }
 }