/**
  * Toggle the user's subscription to a channel.
  *
  * @param int $channelId The ID of the channel to toggle subscription to.
  * @return void
  */
 public function action_subscribe($channelId = "")
 {
     if (!ET::$session->user or !$this->validateToken()) {
         return;
     }
     // If we don't have permission to view this channel, don't proceed.
     if (!ET::channelModel()->hasPermission((int) $channelId, "view")) {
         return;
     }
     // Work out if we're already unsubscribed or not, and switch to the opposite of that.
     $channel = ET::SQL()->select("unsubscribed, lft, rgt")->from("channel c")->from("member_channel mc", "mc.channelId = c.channelId AND mc.memberId = :userId", "left")->bind(":userId", ET::$session->userId)->where("c.channelId", (int) $channelId)->exec()->firstRow();
     // Get all the child channels of this channel.
     $rows = ET::SQL()->select("channelId")->from("channel")->where("lft >= :lft")->bind(":lft", $channel["lft"])->where("rgt <= :rgt")->bind(":rgt", $channel["rgt"])->exec()->allRows();
     $channelIds = array();
     foreach ($rows as $row) {
         $channelIds[] = $row["channelId"];
     }
     // Write to the database.
     ET::channelModel()->setStatus($channelIds, ET::$session->userId, array("unsubscribed" => !$channel["unsubscribed"]));
     // Normally, redirect back to the channel list.
     if ($this->responseType === RESPONSE_TYPE_DEFAULT) {
         redirect(URL("channels"));
     }
     // Otherwise, set a JSON var.
     $this->json("unsubscribed", !$channel["unsubscribed"]);
     $this->render();
 }
예제 #2
0
 /**
  * Create a member.
  *
  * @param array $values An array of fields and their values to insert.
  * @return bool|int The new member ID, or false if there were errors.
  */
 public function create(&$values)
 {
     // Validate the username, email, and password.
     $this->validate("username", $values["username"], array($this, "validateUsername"));
     $this->validate("email", $values["email"], array($this, "validateEmail"));
     $this->validate("password", $values["password"], array($this, "validatePassword"));
     // Hash the password and set the join time.
     $values["password"] = $this->hashPassword($values["password"]);
     $values["joinTime"] = time();
     // MD5 the "reset password" hash for storage (for extra safety).
     $oldHash = isset($values["resetPassword"]) ? $values["resetPassword"] : null;
     if (isset($values["resetPassword"])) {
         $values["resetPassword"] = md5($values["resetPassword"]);
     }
     // Set default preferences.
     if (empty($values["preferences"])) {
         $preferences = array("email.privateAdd", "email.post", "starOnReply");
         foreach ($preferences as $p) {
             $values["preferences"][$p] = C("esoTalk.preferences." . $p);
         }
     }
     $values["preferences"] = serialize($values["preferences"]);
     if ($this->errorCount()) {
         return false;
     }
     // Delete any members with the same email or username but who haven't confirmed their email address.
     ET::SQL()->delete()->from("member")->where("email=:email OR username=:username")->bind(":email", $values["email"])->bind(":username", $values["username"])->where("confirmedEmail", 0)->exec();
     $memberId = parent::create($values);
     $values["memberId"] = $memberId;
     // Create "join" activity for this member.
     ET::activityModel()->create("join", $values);
     // Go through the list of channels and unsubscribe from any ones that have that attribute set.
     $channels = ET::channelModel()->getAll();
     $inserts = array();
     foreach ($channels as $channel) {
         if (!empty($channel["attributes"]["defaultUnsubscribed"])) {
             $inserts[] = array($memberId, $channel["channelId"], 1);
         }
     }
     if (count($inserts)) {
         ET::SQL()->insert("member_channel")->setMultiple(array("memberId", "channelId", "unsubscribed"), $inserts)->exec();
     }
     // Revert the "reset password" hash to what it was before we MD5'd it.
     $values["resetPassword"] = $oldHash;
     return $memberId;
 }
예제 #3
0
 /**
  * Create a member.
  *
  * @param array $values An array of fields and their values to insert.
  * @return bool|int The new member ID, or false if there were errors.
  */
 public function create(&$values)
 {
     // 2016/02 以下チェック不要
     //	// Validate the username, email, and password.
     //	$this->validate("username", $values["username"], array($this, "validateUsername"));
     //	$this->validate("email", $values["email"], array($this, "validateEmail"));
     //	$this->validate("password", $values["password"], array($this, "validatePassword"));
     //
     //	// Hash the password and set the join time.
     //	$values["password"] = $this->hashPassword($values["password"]);
     //	$values["joinTime"] = time();
     // SWCユーザID
     $memberId = $values['memberId'];
     // Set default preferences.
     if (empty($values["preferences"])) {
         $preferences = array("email.privateAdd", "email.post", "starOnReply");
         foreach ($preferences as $p) {
             $values["preferences"][$p] = C("esoTalk.preferences." . $p);
         }
     }
     $values["preferences"] = serialize($values["preferences"]);
     if ($this->errorCount()) {
         return false;
     }
     // メンバーテーブル追加登録
     $memberId = parent::create($values);
     //	$values["memberId"] = $memberId;
     $this->trigger("createAfter", array($values));
     // TODO: "join" のアクティビティログ登録確認要
     // Create "join" activity for this member.
     //	ET::activityModel()->create("join", $values);
     // Go through the list of channels and unsubscribe from any ones that have that attribute set.
     $channels = ET::channelModel()->getAll();
     $inserts = array();
     foreach ($channels as $channel) {
         if (!empty($channel["attributes"]["defaultUnsubscribed"])) {
             $inserts[] = array($memberId, $channel["channelId"], 1);
         }
     }
     if (count($inserts)) {
         ET::SQL()->insert("member_channel")->setMultiple(array("memberId", "channelId", "unsubscribed"), $inserts)->exec();
     }
     return $memberId;
 }
 /**
  * Toggle the user's subscription to a channel.
  *
  * @param int $channelId The ID of the channel to toggle subscription to.
  * @return void
  */
 public function subscribe($channelId = "")
 {
     if (!ET::$session->user or !$this->validateToken()) {
         return;
     }
     // If we don't have permission to view this channel, don't proceed.
     if (!ET::channelModel()->hasPermission((int) $channelId, "view")) {
         return;
     }
     // Work out if we're already unsubscribed or not, and switch to the opposite of that.
     $unsubscribed = !ET::SQL()->select("unsubscribed")->from("member_channel")->where("memberId", ET::$session->userId)->where("channelId", (int) $channelId)->exec()->result();
     // Write to the database.
     ET::channelModel()->setStatus($channelId, ET::$session->userId, array("unsubscribed" => $unsubscribed));
     // Normally, redirect back to the channel list.
     if ($this->responseType === RESPONSE_TYPE_DEFAULT) {
         redirect(URL("channels"));
     }
     // Otherwise, set a JSON var.
     $this->json("unsubscribed", $unsubscribed);
     $this->render();
 }
 /**
  * Show a sheet to edit a member's permissions by changing their account type and groups.
  *
  * @param int $memberId The member's ID.
  * @return void
  */
 public function action_permissions($memberId = "")
 {
     if (!($member = $this->getMember($memberId))) {
         return;
     }
     // If we don't have permission to change the member's permissions, throw an error.
     if (!ET::memberModel()->canChangePermissions($member)) {
         $this->renderMessage(T("Error"), T("message.noPermission"));
         return;
     }
     // Construct a form.
     $form = ETFactory::make("form");
     $form->action = URL("member/permissions/" . $member["memberId"]);
     // Get a list of all possible account types, groups, and permission types.
     $accounts = array(ACCOUNT_ADMINISTRATOR, ACCOUNT_MEMBER);
     $groups = ET::groupModel()->getAll();
     $permissions = array("view" => T("View"), "reply" => T("Reply"), "start" => T("Start"), "moderate" => T("Moderate"));
     // Set the value of the account field in the form to the member's current account.
     $form->setValue("account", $member["account"]);
     // Get the currently selected account from the form input.
     $currentAccount = $form->getValue("account", $member["account"]);
     if (!in_array($currentAccount, $accounts)) {
         $currentAccount = ACCOUNT_MEMBER;
     }
     // Get the currently selected groups from the form input, and a list of collective group IDs.
     $currentGroups = (array) $form->getValue("groups", array_keys($member["groups"]));
     $groupIds = ET::groupModel()->getGroupIds($currentAccount, $currentGroups);
     // Get a list of all channels and their permissions, which we can use to construct a permissions grid.
     $channels = ET::channelModel()->getAll();
     // Create a list of "extra" permissions (eg. being able to access the admin CP, or suspend members.)
     $extraPermissions = array();
     if ($currentAccount == ACCOUNT_ADMINISTRATOR) {
         $extraPermissions[] = T("Access the administrator control panel.");
     }
     // Work out if they will be able to suspend members by going through each group and checking its permissions.
     $canSuspend = false;
     if ($currentAccount == ACCOUNT_ADMINISTRATOR) {
         $canSuspend = true;
     } else {
         foreach ($currentGroups as $group) {
             if (!empty($groups[$group]["canSuspend"])) {
                 $canSuspend = true;
                 break;
             }
         }
     }
     if ($canSuspend) {
         $extraPermissions[] = T("Suspend members.");
     }
     // Handle a post back from the form.
     $redirectURL = URL(memberURL($member["memberId"], $member["username"]));
     if ($form->isPostBack("cancel")) {
         $this->redirect($redirectURL);
     }
     if ($form->validPostBack("save")) {
         // Save the new account and groups.
         ET::memberModel()->setGroups($member, $currentAccount, $currentGroups);
         // Show a message and redirect.
         $this->message(T("message.changesSaved"), "success autoDismiss");
         $this->redirect($redirectURL);
     }
     // Transport data to the view.
     $this->data("form", $form);
     $this->data("accounts", $accounts);
     $this->data("groups", $groups);
     $this->data("groupIds", $groupIds);
     $this->data("permissions", $permissions);
     $this->data("channels", $channels);
     $this->data("member", $member);
     $this->data("extraPermissions", $extraPermissions);
     // For an ajax request, show permission info.
     if ($this->responseType === RESPONSE_TYPE_AJAX) {
         $this->render("member/permissionInfo");
     } else {
         $this->render("member/permissions");
     }
 }
예제 #6
0
 /**
  * Get activity data with the "activity" projection for a certain member (i.e. the activity that should
  * appear on their profile page.)
  *
  * @param array $member The details of the member to get activity for.
  * @param int $offset Offset to start getting results from.
  * @param int $limit Number of results to get.
  * @return array A multi-dimensional array of activity data.
  */
 public function getActivity($member, $offset = 0, $limit = 11)
 {
     // Construct a query that will get all the activity data from the activity table.
     $activity = ET::SQL()->select("activityId")->select("IF(fromMemberId IS NOT NULL,fromMemberId,a.memberId)", "fromMemberId")->select("m.username", "fromMemberName")->select("email")->select("avatarFormat")->select("type")->select("data")->select("NULL", "postId")->select("NULL", "title")->select("NULL", "content")->select("NULL", "start")->select("time")->from("activity a")->from("member m", "m.memberId=IF(fromMemberId IS NOT NULL,fromMemberId,a.memberId)", "left")->where("a.memberId=:memberId")->bind(":memberId", $member["memberId"])->where("a.type IN (:types)")->bind(":types", $this->getTypesWithProjection(self::PROJECTION_ACTIVITY))->orderBy("time DESC")->limit($offset + $limit);
     // Construct a query that will get all of the user's most recent posts.
     // All of the posts will be handled through the "post" activity type.
     $posts = ET::SQL()->select("NULL", "activityId")->select($member["memberId"], "fromMemberId")->select(ET::$database->escapeValue($member["username"]), "fromMemberName")->select(ET::$database->escapeValue($member["email"]), "email")->select(ET::$database->escapeValue($member["avatarFormat"]), "avatarFormat")->select("'postActivity'", "type")->select("NULL", "data")->select("postId")->select("c.title", "title")->select("content")->select("c.startMemberId=p.memberId AND c.startTime=p.time", "start")->select("time")->from("post p")->from("conversation c", "c.conversationId=p.conversationId", "left")->where("memberId=:memberId")->where("p.deleteTime IS NULL")->bind(":memberId", $member["memberId"])->where("c.countPosts>0")->where("c.private=0")->orderBy("time DESC")->limit($offset + $limit);
     ET::channelModel()->addPermissionPredicate($posts);
     // Marry these two queries so we get their activity AND their posts in one resultset.
     $result = ET::SQL()->union($activity)->union($posts)->orderBy("time DESC")->limit($limit)->offset($offset)->exec();
     // Now expand the resultset into a proper array of activity items by running activity type/projection
     // callback functions.
     $activity = array();
     while ($item = $result->nextRow()) {
         // If there's no activity type handler for this item and the "activity" projection, discard it.
         if (empty(self::$types[$item["type"]][self::PROJECTION_ACTIVITY])) {
             continue;
         }
         // Expand the activity data.
         $item["data"] = unserialize($item["data"]);
         // Run the type/projection's callback function. The return value is the activity description and body.
         list($item["description"], $item["body"]) = call_user_func_array(self::$types[$item["type"]][self::PROJECTION_ACTIVITY], array(&$item, $member)) + array(null, null);
         $activity[] = $item;
     }
     return $activity;
 }
 /**
  * Show a page where a conversation's channel can be changed.
  *
  * @param int $conversationId The ID of the conversation to edit.
  * @return void
  */
 public function action_changeChannel($conversationId = "")
 {
     // Get the conversation.
     if (!$conversationId) {
         $conversation = ET::conversationModel()->getEmptyConversation();
     } elseif (!($conversation = $this->getConversation($conversationId))) {
         return;
     }
     // Do we have permission to do this?
     if (!$conversation["canModerate"] and $conversation["startMemberId"] != ET::$session->userId) {
         $this->renderMessage(T("Error"), T("message.noPermission"));
         return;
     }
     // Get the channels, and add a "start" permission field to each of them.
     $channels = ET::channelModel()->get();
     $groupModel = ET::groupModel();
     $groupIds = ET::$session->getGroupIds();
     foreach ($channels as $k => &$channel) {
         if (!empty($channel["unsubscribed"])) {
             unset($channels[$k]);
             continue;
         }
         $channel["start"] = $groupModel->groupIdsAllowedInGroupIds($groupIds, $channel["permissions"]["start"], true);
     }
     // Make a form to submit to the save page.
     $form = ETFactory::make("form");
     $form->action = URL("conversation/save/" . $conversation["conversationId"]);
     $form->setValue("channel", $conversation["channelId"]);
     // Pass along data to the view.
     $this->data("conversation", $conversation);
     $this->data("channels", $channels);
     $this->data("form", $form);
     $this->render("conversation/changeChannel");
 }
 /**
  * Delete a channel.
  *
  * @param int $channelId The ID of the channel to delete.
  * @return void
  */
 public function action_delete($channelId)
 {
     // Get the channel.
     $channels = ET::channelModel()->getAll();
     if (!isset($channels[$channelId])) {
         return;
     }
     $channel = $channels[$channelId];
     // Set up the form.
     $form = ETFactory::make("form");
     $form->action = URL("admin/channels/delete/" . $channelId);
     $form->setValue("method", "move");
     // If the form was submitted...
     if ($form->validPostBack("delete")) {
         // If this is the last channel, we can't delete it.
         if (count($channels) == 1) {
             $this->message(T("message.cannotDeleteLastChannel"), "warning");
         } else {
             // Attempt to delete the channel.
             $model = ET::channelModel();
             $model->deleteById($channelId, $form->getValue("method") == "move" ? (int) $form->getValue("moveToChannelId") : false);
             // If there were errors, pass them on to the form.
             if ($model->errorCount()) {
                 $form->errors($model->errors());
             } else {
                 $this->message(T("message.changesSaved"), "success autoDismiss");
                 $this->redirect(URL("admin/channels"));
             }
         }
     }
     $this->data("channels", $channels);
     $this->data("channel", $channel);
     $this->data("form", $form);
     $this->render("admin/deleteChannel");
 }
예제 #9
0
 /**
  * Set the channel of a conversation.
  *
  * @param array $conversation The conversation to set the channel for. The conversation array's channelId
  * 		attribute will be updated.
  * @param int $channelId Whether or not the conversation is locked.
  * @return bool Returns true on success, or false if there is an error.
  */
 public function setChannel(&$conversation, $channelId)
 {
     if (!ET::channelModel()->hasPermission($channelId, "start")) {
         $this->error("channelId", T("message.noPermission"));
     }
     if ($this->errorCount()) {
         return false;
     }
     // Decrease the conversation/post count of the old channel.
     ET::SQL()->update("channel")->set("countConversations", "countConversations - 1", false)->set("countPosts", "countPosts - :posts", false)->bind(":posts", $conversation["countPosts"])->where("channelId=:channelId")->bind(":channelId", $conversation["channelId"])->exec();
     $this->updateById($conversation["conversationId"], array("channelId" => $channelId));
     // Increase the conversation/post count of the new channel.
     ET::SQL()->update("channel")->set("countConversations", "countConversations + 1", false)->set("countPosts", "countPosts + :posts", false)->bind(":posts", $conversation["countPosts"])->where("channelId=:channelId")->bind(":channelId", $channelId)->exec();
     $conversation["channelId"] = $channelId;
     return true;
 }
 /**
  * Given the channel slug from a request, work out which channels are selected, whether or not to include
  * descendant channels in the results, and construct a full list of channel IDs to consider when getting the
  * list a conversations.
  *
  * @param string $channelSlug The channel slug from the request.
  * @return array An array containing:
  * 		0 => a full list of channel information.
  * 		1 => the list of currently selected channel IDs.
  * 		2 => the full list of channel IDs to consider (including descendant channels of selected channels.)
  * 		3 => whether or not descendant channels are being included.
  */
 protected function getSelectedChannels($channelSlug = "")
 {
     // Get a list of all viewable channels.
     $channelInfo = ET::channelModel()->get();
     // Get a list of the currently selected channels.
     $currentChannels = array();
     $includeDescendants = true;
     if (!empty($channelSlug)) {
         $channels = explode(" ", $channelSlug);
         // If the first channel is empty (ie. the URL is conversations/+channel-slug), set a flag
         // to turn off the inclusion of descendant channels when considering conversations.
         if ($channels[0] == "") {
             $includeDescendants = false;
             array_shift($channels);
         }
         // Go through the channels and add their IDs to the list of current channels.
         foreach ($channels as $channel) {
             foreach ($channelInfo as $id => $c) {
                 if ($c["slug"] == $channel) {
                     $currentChannels[] = $id;
                     break;
                 }
             }
         }
     }
     // Get an array of channel IDs to consider when getting the list of conversations.
     // If we're not including descendants, this is the same as the list of current channels.
     if (!$includeDescendants) {
         $channelIds = $currentChannels;
     } else {
         $channelIds = array();
         foreach ($currentChannels as $id) {
             $channelIds[] = $id;
             $rootUnsubscribed = !empty($channelInfo[$id]["unsubscribed"]);
             foreach ($channelInfo as $channel) {
                 if ($channel["lft"] > $channelInfo[$id]["lft"] and $channel["rgt"] < $channelInfo[$id]["rgt"] and (empty($channel["unsubscribed"]) or $rootUnsubscribed)) {
                     $channelIds[] = $channel["channelId"];
                 }
             }
         }
     }
     // If by now we don't have any channel IDs, we must be viewing "all channels." In this case,
     // add all the channels.
     if (empty($channelIds)) {
         foreach ($channelInfo as $id => $channel) {
             if (empty($channel["unsubscribed"])) {
                 $channelIds[] = $id;
             }
         }
     }
     return array($channelInfo, $currentChannels, $channelIds, $includeDescendants);
 }
예제 #11
0
 /**
  * Add a WHERE predicate to an SQL query that gets conversations which should appear as notifications.
  * The conversations must be private and the user must be allowed, or the user must have starred the
  * conversation. The user must also have permission to view the channel that the conversation is in.
  *
  * @param ETSQLQuery $sql The SQL query to add the predicate to.
  * @return void
  */
 private function addNotificationConversationPredicate(&$sql)
 {
     $sql->where("((s.allowed=1 AND c.private=1) OR s.starred=1) AND s.muted!=1 AND ((s.type='member' AND s.id=:userId) OR (s.type='group' AND s.id IN (:groupIds)))")->bind(":userId", ET::$session->userId)->bind(":groupIds", ET::$session->getGroupIds());
     ET::channelModel()->addPermissionPredicate($sql);
 }
예제 #12
0
 /**
  * Perform a fresh installation of the esoTalk database. Create the table structure and insert default data.
  *
  * @param array $info An array of information gathered from the installation form.
  * @return void
  */
 public function install($info)
 {
     // Create the table structure.
     $this->structure(true);
     // 2016/02 インストール時処理 修正
     // admin ユーザ登録は不要
     //	// Create the administrator member.
     //	$member = array(
     //		"username" => $info["adminUser"],
     //		"email" => $info["adminEmail"],
     //		"password" => $info["adminPass"],
     //		"account" => "Administrator",
     //		"confirmed" => true
     //	);
     //	ET::memberModel()->create($member);
     //
     //	// Set the session's userId and user information variables to the administrator, so that all entities
     //	// created below will be created by the administrator user.
     //	ET::$session->userId = 1;
     //	ET::$session->user = ET::memberModel()->getById(1);
     // Create the moderator group.
     ET::groupModel()->create(array("name" => "Moderator", "canSuspend" => true));
     // Create the General Discussion channel.
     $id = ET::channelModel()->create(array("title" => "全般", "slug" => slug("General Discussion")));
     ET::channelModel()->setPermissions($id, array(GROUP_ID_GUEST => array("view" => true), GROUP_ID_MEMBER => array("view" => true, "reply" => true, "start" => true), 1 => array("view" => true, "reply" => true, "start" => true, "moderate" => true)));
     // Create the Staff Only channel.
     $id = ET::channelModel()->create(array("title" => "Staff Only", "slug" => slug("Staff Only")));
     ET::channelModel()->setPermissions($id, array(1 => array("view" => true, "reply" => true, "start" => true, "moderate" => true)));
     // Set the flood control config setting to zero so that we can create two conversations in a row.
     ET::$config["esoTalk.conversation.timeBetweenPosts"] = 0;
     // Create a welcome conversation.
     ET::conversationModel()->create(array("title" => "Welcome to " . $info["forumTitle"] . "!", "content" => "[b]Welcome to " . $info["forumTitle"] . "![/b]\n\n" . $info["forumTitle"] . " is powered by [url=http://esotalk.org]esoTalk[/url], the simple, fast, free web-forum.\n\nFeel free to edit or delete this conversation. Otherwise, it's time to get posting!\n\nAnyway, good luck, and we hope you enjoy using esoTalk.", "channelId" => 1));
     // Create a helpful private conversation with the administrator.
     ET::conversationModel()->create(array("title" => "Pssst! Want a few tips?", "content" => "Hey {$info["adminUser"]}, congrats on getting esoTalk installed!\n\nCool! Your forum is now good-to-go, but you might want to customize it with your own logo, design, and settings—so here's how.\n\n[h]Changing the Logo[/h]\n\n1. Go to the [url=" . C("esoTalk.baseURL") . "admin/settings]Forum Settings[/url] section of your administration panel.\n2. Select 'Show an image in the header' for the 'Forum header' setting.\n3. Find and select the image file you wish to use.\n4. Click 'Save Changes'. The logo will automatically be resized so it fits nicely in the header.\n\n[h]Changing the Appearance[/h]\n\n1. Go to the [url=" . C("esoTalk.baseURL") . "admin/appearance]Appearance[/url] section of your administration panel.\n2. Choose colors for the header, page background, or select a background image. (More skins will be available soon.)\n3. Click 'Save Changes', and your forum's appearance will be updated!\n\n[h]Managing Channels[/h]\n\n'Channels' are a way to categorize conversations in your forum. You can create as many or as few channels as you like, nest them, and give them custom permissions.\n\n1. Go to the [url=" . C("esoTalk.baseURL") . "admin/channels]Channels[/url] section of your administration panel.\n2. Click 'Create Channel' and fill out a title, description, and select permissions to add a new channel.\n3. Drag and drop channels to rearrange and nest them.\n\n[h]Getting Help[/h]\n\nIf you need help, come and give us a yell at the [url=http://esotalk.org/forum]esoTalk Support Forum[/url]. Don't worry—we don't bite!", "channelId" => 1), array(array("type" => "member", "id" => 1)));
     // All done!
 }
예제 #13
0
 function renderChannelsField($form)
 {
     $channels = ET::channelModel()->getAll();
     $titles = array();
     foreach ($channels as $channel) {
         $titles[] = $channel["title"];
         $slug[] = $channel["slug"];
     }
     // Set the keys of the titles array
     // the same as the values.
     $channelslist = array_combine($slug, $titles);
     $channelslist[] = T("(no channels excluded)");
     // Set up the select element.
     $settings = array("style" => "width:200px", "size" => count($channelslist), "multiple" => "multiple");
     // Return the restore select element.
     return $form->select("channels[]", $channelslist, $settings);
 }
 /**
  * Show a sheet to create a new group.
  *
  * @return void
  */
 public function action_create()
 {
     // Set up the form.
     $form = ETFactory::make("form");
     $form->action = URL("admin/groups/create");
     // Was the cancel button pressed?
     if ($form->isPostBack("cancel")) {
         $this->redirect(URL("admin/groups"));
     }
     // Was the save button pressed?
     if ($form->validPostBack("save")) {
         $data = array("name" => $form->getValue("name"), "canSuspend" => (bool) $form->getValue("canSuspend"), "private" => (bool) $form->getValue("private"));
         $model = ET::groupModel();
         $groupId = $model->create($data);
         // If there were errors, pass them on to the form.
         if ($model->errorCount()) {
             $form->errors($model->errors());
         } else {
             // Do we want to give this group the moderate permission on all existing channels?
             if ($form->getValue("giveModeratePermission")) {
                 // Go through all the channels and construct an array of rows to insert into the channel_group table.
                 $channels = ET::channelModel()->getAll();
                 $inserts = array();
                 foreach ($channels as $id => $channel) {
                     $inserts[] = array($id, $groupId, 1, 1, 1, 1);
                 }
                 // Insert them!
                 ET::SQL()->insert("channel_group")->setMultiple(array("channelId", "groupId", "view", "reply", "start", "moderate"), $inserts)->setOnDuplicateKey("moderate", 1)->exec();
             }
             // Redirect back to the groups page.
             $this->redirect(URL("admin/groups"));
         }
     }
     $this->data("form", $form);
     $this->data("group", null);
     $this->render("admin/editGroup");
 }
예제 #15
0
 /**
  * Set the channel of a conversation.
  *
  * @param array $conversation The conversation to set the channel for. The conversation array's channelId
  * 		attribute will be updated.
  * @param int $channelId Whether or not the conversation is locked.
  * @return bool Returns true on success, or false if there is an error.
  */
 public function setChannel(&$conversation, $channelId)
 {
     if (!ET::channelModel()->hasPermission($channelId, "start")) {
         $this->error("channelId", T("message.noPermission"));
     }
     if ($this->errorCount()) {
         return false;
     }
     $this->updateById($conversation["conversationId"], array("channelId" => $channelId));
     $conversation["channelId"] = $channelId;
     return true;
 }