| 27 | | |
| 28 | | public function show($username, $id) |
| 29 | | { |
| 30 | | $this->pageTitle = 'Classrooms'; |
| 31 | | $this->layout = 'berlin'; //$this->Blog->field; |
| 32 | | |
| 33 | | $conditions = array("Subject.status"=>1, "Subject.id"=>$id); |
| 34 | | $fields = array("Subject.id", "Subject.name", "Subject.program_id", "Subject.created"); |
| 35 | | $order = "Subject.name DESC"; |
| 36 | | |
| 37 | | $this->set('blog', $this->Edublog->blog($username)); |
| 38 | | |
| 39 | | $this->set('data', $this->Message->findAll($conditions, $fields, $order, null, null, 2, 2)); |
| 40 | | } |
| 41 | | |
| 42 | | public function message($user_id) |
| 43 | | { |
| | 33 | |
| | 34 | public function message($username) // show form to send message to teacher |
| | 35 | { |
| 68 | | $this->set('Element', $this->Portal->statics()); // Using Portal component |
| 69 | | } |
| 70 | | |
| 71 | | public function search() |
| 72 | | { |
| 73 | | $this->layout = 'ajax'; |
| 74 | | |
| 75 | | $this->pageTitle = 'Write Message'; |
| 76 | | |
| 77 | | $conditions = array("User.username ~* '".'ad' ."'"); |
| 78 | | |
| 79 | | $fields = array("User.username", "User.id"); |
| 80 | | |
| 81 | | $order = "User.username"; |
| 82 | | |
| 83 | | $this->Message->User->unbindModel($this->Message->User->notNow); |
| 84 | | |
| 85 | | $limit = 15; |
| 86 | | |
| 87 | | $this->set('data', $this->Message->User->findAll($conditions, $fields, $order, $limit)); |
| 88 | | |
| 89 | | $this->render('search', 'ajax'); |
| 90 | | } |
| 91 | | |
| 92 | | public function chat($nick='mononeuron') |
| 93 | | { |
| | 60 | $this->Portal->statics(); // Using Portal component |
| | 61 | } |
| | 62 | |
| | 63 | public function chat($nick='mononeuron') |
| | 64 | { |
| 129 | | } |
| 130 | | |
| 131 | | /**=== ADMIN METHODS ===**/ |
| 132 | | public function admin_general() |
| 133 | | { |
| 134 | | if ($this->Auth->user('group_id') != 1) |
| 135 | | { |
| 136 | | $this->redirect('/admin/messages/listing'); |
| 137 | | } |
| 138 | | |
| 139 | | $this->layout = 'admin'; |
| 140 | | |
| 141 | | if (!empty($this->data["Message"])) |
| 142 | | { |
| 143 | | $this->Sanitize = new Sanitize; |
| 144 | | |
| 145 | | $this->Sanitize->html($this->data["Message"]["title"]); |
| 146 | | |
| 147 | | $this->Sanitize->html($this->data["Message"]["body"]); |
| 148 | | |
| 149 | | $this->Message->User->unbindModel( |
| 150 | | array( |
| 151 | | "hasMany"=>array( |
| 152 | | "Entry", "News", "Category", "Lesson", "Podcast", "Bookmark"))); |
| 153 | | |
| 154 | | $conditions = array("active"=>1); |
| 155 | | |
| 156 | | $fields = array("id"); |
| 157 | | |
| 158 | | $data = $this->User->findAll($conditions, $fields); |
| 159 | | |
| 160 | | $j = 0; //counter |
| 161 | | |
| 162 | | $this->data["Message"]["sender_id"] = $this->Auth->user('id'); |
| 163 | | |
| 164 | | //exit(print_r($data)); |
| 165 | | |
| 166 | | foreach($data as $val) |
| 167 | | { |
| 168 | | $this->Message->create(); |
| 169 | | |
| 170 | | //exit(print_r($val)); |
| 171 | | |
| 172 | | $this->data["Message"]["user_id"] = $val["User"]["id"]; |
| 173 | | |
| 174 | | if ($this->Message->save($this->data["Message"])) |
| 175 | | { |
| 176 | | $j++; |
| 177 | | } |
| 178 | | else |
| 179 | | { |
| 180 | | exit('error on save'); |
| 181 | | } |
| 182 | | } |
| 183 | | $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); |
| 184 | | } |
| 185 | | } |
| 186 | | |
| 187 | | private function sendMail($user_id, $username, $title) |
| | 100 | } |
| | 101 | private function sendMail($user_id, $username, $title) |
| 220 | | } |
| 221 | | |
| | 134 | } |
| | 135 | |
| | 136 | /**=== ADMIN METHODS ===**/ |
| | 137 | public function admin_general() // send a general message to all commnunity |
| | 138 | { |
| | 139 | if ($this->Auth->user('group_id') != 1) |
| | 140 | { |
| | 141 | $this->redirect('/admin/messages/listing'); |
| | 142 | } |
| | 143 | |
| | 144 | $this->layout = 'admin'; |
| | 145 | |
| | 146 | if (!empty($this->data["Message"])) |
| | 147 | { |
| | 148 | $this->Sanitize = new Sanitize; |
| | 149 | |
| | 150 | $this->Sanitize->html($this->data["Message"]["title"]); |
| | 151 | |
| | 152 | $this->Sanitize->html($this->data["Message"]["body"]); |
| | 153 | |
| | 154 | $this->Message->User->unbindModel( |
| | 155 | array( |
| | 156 | "hasMany"=>array( |
| | 157 | "Entry", "News", "Category", "Lesson", "Podcast", "Bookmark"))); |
| | 158 | |
| | 159 | $conditions = array("active"=>1); |
| | 160 | |
| | 161 | $fields = array("id"); |
| | 162 | |
| | 163 | $data = $this->User->findAll($conditions, $fields); |
| | 164 | |
| | 165 | $j = 0; //counter |
| | 166 | |
| | 167 | $this->data["Message"]["sender_id"] = $this->Auth->user('id'); |
| | 168 | |
| | 169 | //exit(print_r($data)); |
| | 170 | |
| | 171 | foreach($data as $val) |
| | 172 | { |
| | 173 | $this->Message->create(); |
| | 174 | |
| | 175 | //exit(print_r($val)); |
| | 176 | |
| | 177 | $this->data["Message"]["user_id"] = $val["User"]["id"]; |
| | 178 | |
| | 179 | if ($this->Message->save($this->data["Message"])) |
| | 180 | { |
| | 181 | $j++; |
| | 182 | } |
| | 183 | else |
| | 184 | { |
| | 185 | exit('error on save'); |
| | 186 | } |
| | 187 | } |
| | 188 | $this->msgFlash($j . ' messages sent', '/admin/messages/listing'); |
| | 189 | } |
| | 190 | } |
| | 191 | |