Esempio n. 1
0
 public function actionSend($type = 'private', $toUserId = null)
 {
     $types = array('system', 'user', 'private', 'group');
     RAssert::is_true(in_array($type, $types));
     $data = array('type' => $type);
     if ($toUserId != null) {
         $data['toUser'] = User::get($toUserId);
     }
     if (Rays::isPost()) {
         if (isset($_POST['new'])) {
             if (isset($_POST['receiverName'])) {
                 $data['sendForm'] = array('receiver' => $_POST['receiverName']);
             }
             $this->render('send', $data, false);
             return;
         }
         $form = $_POST;
         $config = array(array('field' => 'title', 'label' => 'Title', 'rules' => 'trim|required'), array('field' => 'msg-content', 'label' => 'Content', 'rules' => 'trim|required'), array('field' => 'receiver', 'label' => 'Receiver', 'rules' => 'required'), array('field' => 'type', 'label' => 'Message type', 'rules' => 'trim|required'));
         $validation = new RValidation($config);
         if ($validation->run()) {
             $receiver = User::find("name", $_POST['receiver'])->first();
             if ($receiver == null) {
                 $this->flash("error", "No such user.");
             } else {
                 $senderId = 0;
                 if (isset($_POST['sender'])) {
                     //mainly for group and system message
                     $senderId = $_POST['sender'];
                 } else {
                     $senderId = Rays::user()->id;
                 }
                 $title = isset($_POST['title']) ? trim($_POST['title']) : "";
                 $msgContent = RHtml::encode($_POST['msg-content']);
                 $message = Message::sendMessage($_POST['type'], $senderId, $receiver->id, $title, $msgContent, null, 1);
                 if (isset($message->id) && $message->id != '') {
                     $this->flash("message", "Send message successfully.");
                     $this->redirectAction('message', 'view');
                     return;
                 } else {
                     $this->flash("message", "Send message failed.");
                 }
             }
         }
         $data['sendForm'] = $form;
         if ($validation->getErrors() != '') {
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->render('send', $data, false);
 }
Esempio n. 2
0
 /**
  * Category administration
  */
 public function actionAdmin()
 {
     $data = array();
     if (Rays::isPost()) {
         if (isset($_POST['sub_items'])) {
             $items = $_POST['sub_items'];
             if (is_array($items)) {
                 foreach ($items as $item) {
                     if (!is_numeric($item)) {
                         return;
                     } else {
                         $cat = Category::get($item);
                         if ($cat->pid == 0) {
                             continue;
                         }
                         $cat->delete();
                     }
                 }
             }
         }
         if (isset($_POST['cat-name']) && isset($_POST['parent-id'])) {
             $name = trim($_POST['cat-name']);
             $pid = $_POST['parent-id'];
             if (is_numeric($pid)) {
                 if ($name == '') {
                     $this->flash('error', 'Category name cannot be blank.');
                 } else {
                     $result = Category::get($pid);
                     if ($result != null) {
                         $newCat = new Category();
                         $newCat->name = RHtml::encode(trim($name));
                         $newCat->pid = $pid;
                         $newCat->save();
                         $this->flash('message', 'Category ' . $name . " was created successfully.");
                     } else {
                         $this->flash('error', 'Parent category not exists.');
                     }
                 }
             }
         }
     }
     $data['categories'] = Category::find()->all();
     $this->layout = 'admin';
     $this->setHeaderTitle('Category administration');
     $this->render('admin', $data, false);
 }
Esempio n. 3
0
 public function actionEdit($topicId)
 {
     $topic = Topic::get($topicId);
     if (Rays::isPost()) {
         $validation = new RValidation(array(array("field" => "title", "label" => "Title", "rules" => "trim|required"), array("field" => "post-content", "label" => "Content", "rules" => "trim|required")));
         $topic->title = $_POST['title'];
         $topic->content = RHtml::encode($_POST['post-content']);
         if ($validation->run()) {
             $topic->save();
             $this->flash("message", "Post " . $topic->title . " was updated successfully.");
             $this->redirectAction('post', 'view', $topic->id);
         } else {
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $group = Group::get($topic->groupId);
     $data = array("type" => "edit", "topic" => $topic, 'group' => $group, 'groupId' => $group->id);
     $data['groups'] = GroupUser::getGroups(GroupUser::find("userId", Rays::user()->id)->join("group")->order_desc("groupId")->all());
     $this->layout = 'user';
     $this->addCss('/public/css/post.css');
     $this->setHeaderTitle("Edit post: " . $topic->title);
     $this->render('edit', $data, false);
 }
Esempio n. 4
0
 public function actionEdit($adId, $type)
 {
     $ad = Ads::get($adId);
     RAssert::not_null($ad);
     $data = ['ad' => $ad, 'edit' => true, 'type' => $type];
     if (Rays::isPost()) {
         $rules = array(array('field' => 'ads-title', 'label' => 'Ads title', 'rules' => 'trim|required|min_length[5]|max_length[255]'), array('field' => 'ads-content', 'label' => 'Ads content', 'rules' => 'required'), array('field' => 'paid-price', 'label' => 'Paid price', 'rules' => 'trim|required|number'));
         $validation = new RValidation($rules);
         if ($validation->run()) {
             $ad->title = $_POST['ads-title'];
             $ad->content = RHtml::encode($_POST['ads-content']);
             $ad->save();
             $this->flash('message', 'Your ads was edited successfully.');
             $redirect = null;
             switch ($type) {
                 case Ads::APPROVED:
                     $redirect = 'published';
                     break;
                 case Ads::APPLYING:
                     $redirect = 'applying';
                     break;
                 case Ads::BLOCKED:
                     $redirect = 'blocked';
                     break;
             }
             $this->redirectAction('ads', 'view', $redirect);
         } else {
             $data['applyForm'] = $_POST;
             $data['validation_errors'] = $validation->getErrors();
         }
     }
     $this->setHeaderTitle("Edit Advertisement");
     $this->render('apply', $data, false);
 }
Esempio n. 5
0
<?php

$baseUrl = Rays::app()->getBaseUrl();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title><?php 
echo RHtml::encode(Rays::app()->client()->getHeaderTitle());
?>
</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="language" content="en"/>
    <meta name="description" content=""/>
    <link rel="shortcut icon" href="<?php 
echo $baseUrl;
?>
/public/images/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" type="text/css" href="<?php 
echo $baseUrl;
?>
/public/bootstrap-3.0/css/bootstrap.min.css"/>

    <link rel="stylesheet" type="text/css" href="<?php 
echo $baseUrl;
?>
/public/css/main.css"/>
    <link rel="stylesheet" type="text/css" href="<?php 
echo $baseUrl;
Esempio n. 6
0
 public function actionDecline($censorId = null)
 {
     $censor = Censor::get($censorId);
     if ($censor !== null) {
         $groupUser = new GroupUser();
         $groupUser->groupId = $censor->secondId;
         $groupUser->userId = $censor->firstId;
         $groupUser->joinTime = date('Y-m-d H:i:s');
         $groupUser->status = 1;
         if (!GroupUser::isUserInGroup($groupUser->userId, $groupUser->groupId)) {
             $this->flash("message", "The request is processed.");
             $group = Group::get($groupUser->groupId);
             $title = "Join group request declined";
             $content = 'Group creator have declined your request of joining in group ' . RHtml::linkAction('group', $group->name, 'detail', $group->id);
             $content = RHtml::encode($content);
             Message::sendMessage("group", $group->id, $groupUser->userId, $title, $content);
         } else {
             $this->flash("warning", "TA is already a member of this group.");
         }
         $censor->fail();
         $this->redirectAction('message', 'view');
     }
 }
Esempio n. 7
0
 /**
  * Process VIP
  * by songrenchu
  */
 public function actionProcessVIP()
 {
     $this->setHeaderTitle('Censor VIP');
     $this->layout = 'admin';
     $data = array();
     if (isset($_GET['censorId']) && isset($_GET['op'])) {
         $censor = Censor::get($_GET['censorId']);
         if ($censor !== null) {
             if ((int) $_GET['op'] === 0) {
                 $user = User::get($censor->firstId);
                 $user->roleId = Role::VIP_ID;
                 $user->save();
                 $censor->pass();
                 $content = "Congratulations, " . RHtml::linkAction('user', $user->name, 'view', $user->id) . "!<br/> Your VIP application is accepted by Administrator.";
                 Message::sendMessage("system", 0, $user->id, "VIP application accepted", RHtml::encode($content), '');
             } else {
                 $censor->fail();
                 $user = User::get($censor->firstId);
                 $content = "Sorry, " . RHtml::linkAction('user', $user->name, 'view', $user->id) . "!<br/> Your VIP application is declined by Administrator.";
                 Message::sendMessage("system", 0, $user->id, "VIP application declined", RHtml::encode($content), '');
             }
         }
         $this->redirectAction('user', 'processVIP');
     }
     $curPage = $this->getPage("page");
     $pageSize = $this->getPageSize("pagesize", 5);
     $query = Censor::find(['status', Censor::UNPROCESS, 'typeId', (new Censor())->getTypeId("apply_vip")]);
     $count = $data['count'] = $query->count();
     $applications = $query->order_desc("id")->range(($curPage - 1) * $pageSize, $pageSize);
     $data['applications'] = $applications;
     $users = [];
     foreach ($applications as $apply) {
         $user = User::get($apply->firstId);
         $users[] = $user;
     }
     $data['users'] = $users;
     $url = RHtml::siteUrl('user/processVIP');
     $pager = new RPager('page', $count, $pageSize, $url, $curPage);
     $pager = $pager->showPager();
     $data['pager'] = $pager;
     $this->render('process_vip', $data, false);
 }
Esempio n. 8
0
 /**
  * Recommend all selected groups to every selected users
  * @param $groups
  * @param $users
  */
 public static function recommendGroups($groups, $users, $words = '')
 {
     foreach ($users as $userId) {
         $html = '<div class="row recommend-groups">';
         $count = 0;
         if (!empty($groups)) {
             foreach ($groups as $groupId) {
                 if ($count % 4 == 0) {
                     if ($count > 0) {
                         $html .= '</div><div class="clearfix" style="margin-top: 15px;"></div>';
                     }
                     $html .= '<div class="row">';
                 }
                 $group = Group::get($groupId);
                 if (null != $group) {
                     $censor = new Censor();
                     $censor = $censor->joinGroupApplication($userId, $group->id);
                     $html .= '<div class="col-lg-3 recommend-group-item" style="padding: 5px;overflow: hidden;">';
                     $picture = isset($group->picture) && $group->picture != '' ? $group->picture : Group::$defaults['picture'];
                     $src = RImage::styleSrc($picture, Group::getPicOptions());
                     $html .= RHtml::image($src, $group->name);
                     $html .= '<br/>' . RHtml::linkAction('group', $group->name, 'detail', $group->id);
                     $html .= '<br/>' . RHtml::linkAction('group', 'Accept', 'accept', $censor->id, array('class' => 'btn btn-xs btn-success'));
                     $html .= '</div>';
                     $count++;
                 }
             }
             $html .= '</div>';
         }
         $html .= '</div>';
         $html .= '<div class="recommend-content">' . RHtml::encode($words) . '</div>';
         Message::sendMessage('system', 0, $userId, 'Groups recommendation', $html, date('Y-m-d H:i:s'));
     }
 }