====Suggestions Message Board==== {{lastedit}} This action will allow your Wikka installation to have a Message Board. Before you even try using the script you will need to have the following table inside your wikka mysql database : %%(sql)CREATE TABLE `wikka_suggestions` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT , `title` VARCHAR( 200 ) NOT NULL , `postby` VARCHAR( 100 ) NOT NULL , `time` DATETIME NOT NULL , `status` ENUM( 'I', 'R', 'P' ) NOT NULL , `content` TEXT NOT NULL , `parent` INT UNSIGNED DEFAULT '0' NOT NULL , PRIMARY KEY ( `id` ) , INDEX ( `title` ) ) COMMENT = 'suggestions table for the Wikka ...';%% After this is done you will also need the **/Wikka/actions/msgboard.php** with the following contents: %%(php)LoadAll("SELECT * FROM ".$this->config["table_prefix"]."suggestions ORDER BY parent, time"); /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- UTILITY FUNCTIONS ** --------------------------------------------------------------------------------------------------------------------------------- */ // used for returning an array structure from the MySQL ... function GetAllSuggestions($arr) { $finarr = array(); // lets build the maintable... foreach($arr as $i => $ar) { // handle the parents first... if ($ar['parent'] == 0) { $id = $ar['id']; $finarr[$ar['id']] = array(); } else // handle the children... { $id = $ar['parent']; } foreach($ar as $idx=>$a) { $a = stripslashes($a); } // put them in the big table ... $finarr[$id][] = $ar; } return $finarr; } // used for returning any Status from single letter to whole word .. : 'I' becomes 'Implemented' function GetStatusStr($str) { if ($str == 'I') $str = "Implemented"; elseif ($str == 'R') $str = "Rejected"; elseif ($str == 'P') $str = "Pending"; return $str; } // used for adding a dropdown-choose-status field for various parts of the script ... function AddStatusDropDown($status) { $st = array( 'Rejected' => 0, 'Implemented' => 0, 'Pending' => 0); $st[GetStatusStr($status)] = 1; $finrow = "\n\t\t\t\n"; //var_dump($finrow); return $finrow; } function GetTitleFromID($id, $arr) { foreach (GetAllSuggestions($arr) as $idx => $data) { if ($id == $data['id']) return $data['title']; } } // used on sorting the "Manage subscriptions" Table with various configurations... function SortBy($arr, $func, $val) { $res = array(); if ($func == 'author') { if ($val && $val!= '') { foreach($arr as $i=>$sug) { if ($sug['postby'] == $val) $res[] = $sug; } return $res; } else return $arr; } elseif ($func == 'replies') { function replies($a, $b) { //var_dump($add); //var_dump($i); static $add = true; static $i = 0; if ($a['replies']){} $i += ($add) ? 1 : 0 ; $add = false; } } elseif ($func == 'status') { if ($val && $val!= '') { foreach($arr as $i=>$sug) { if ($sug['status'] == $val) $res[] = $sug; } return $res; } else return $arr; } else { return $arr; } } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- DISPLAY ALL SUGGESTION TOPICS ** --------------------------------------------------------------------------------------------------------------------------------- */ if ($phase == 'manage_sugs') { $sug_arr = GetAllSuggestions($all_sugs); $sort_get = (isset($_GET['sort'])) ? $_GET['sort'] : 'all'; $name_get = (isset($_GET['name'])) ? $_GET['name'] : 'all'; $status_get = (isset($_GET['status_sort'])) ? $_GET['status_sort'] : 'all'; $sort_get_up = ($_GET['sort_up']) ? ($_GET['sort_up']+0) : (1) ; $parents = array(); if (!count($sug_arr) == 0) { foreach($sug_arr as $id => $data) { $cnt = array( 'replies' => (count($data)-1) ); $parents[] = $data[0] + $cnt; } $out = $this->Format("==== Suggestions Index ==== //This page contains all the ".( ($_GET['status_sort']!='all') ? GetStatusStr($_GET['status_sort']).' ' : ' ')."suggestions made ".( ($_GET['name'] != 'all' ) ? 'by '.$_GET['name'].' ' : '')."about this Wikka// ----"); // okie .. now we have the array holding the parent-suggestions ... lets make it happen .. $out .= $this->FormOpen("","","get"); // Add New Suggestion Thread if ( $this->HasAccess("comment") || $this->HasAccess("write") || $this->IsAdmin() ) { $out .= "Href("","", "phase=add_sug")."\">Add Suggestion Thread"; } // Status Sorting ... $out .= " | Show only "; $st = array( 'Rejected' => 0, 'Implemented' => 0, 'Pending' => 0); if ($status_get != 'all') { $st[GetStatusStr($status_get)] = 1;} $out .= "\n\t\t\t"; // Search By Author $out .= " suggested by "; $out .= ""; $st = array(); $tot = 0; foreach($this->LoadAll("SELECT id,postby FROM ".$this->config['table_prefix']."suggestions WHERE parent = '0'") as $idx => $data) { if ( ($st[$data['postby']]) || ($st[$data['postby']] > 1) ) $st[$data['postby']] += 1; else $st[$data['postby']] = 1; $tot++; } $out .= "\n\t\t\t"; $out .= "\n\t\t\t"; $out .= "\n\t\t".$this->FormClose()."\n\t\t
"; // Created the topmost links bar ... if ($sort_get != 'all') { // sort out the 'title' 'time' or 'postby' if ( ($sort_get == 'title') || ($sort_get == 'time') || ($sort_get == 'status')) // TO FIX !!! // { $res = $this->LoadAll("SELECT * FROM ".$this->config['table_prefix']."suggestions WHERE parent = '0' ORDER BY ".$sort_get); $parents = array(); foreach($res as $idx => $data) { if ($data['parent'] == 0) { $id = $data['id']; $parents[$data['id']] = array(); } else // handle the children... { $id = $data['parent']; } foreach($data as $i => $a) { $a = stripslashes($a); } $parents[$id][] = $data; } foreach($sug_arr as $idx => $info) { $cnt = array( 'replies' => (count($info)-1) ); foreach($parents as $i => $a) { if ($a[0]['id'] == $idx) $parents[$i] = array_merge($a[0] ,$cnt); } } $parents = ($sort_get_up==1)? array_reverse($parents) :$parents ; } elseif ($sort_get == 'replies') { function repliesSB($a, $b) { if ($a["replies"]== $b["replies"]) return 0; return ($a["replies"] > $b["replies"]) ? 1 : -1 ; } function repliesBS($a, $b) { if ($a["replies"]== $b["replies"]) return 0; return ($a["replies"] < $b["replies"]) ? 1 : -1 ; } uasort($parents, "replies".(($sort_get_up==1)?"BS":"SB")) ; } elseif ($sort_get == 'postby') { function postbyBS($a, $b) { if ($a['postby'] == $b['postby']) return 0; return ($a['postby'] < $b['postby']) ? -1 : 1; } function postbySB($a, $b) { if ($a['postby'] == $b['postby']) return 0; return ($a['postby'] < $b['postby']) ? 1 : -1; } uasort($parents, 'postby'.(($sort_get_up==-1)?'BS':'SB')); } } // The author filtering ... if ($name_get !='all') { $res = $parents; $parents = array(); foreach($res as $i=>$info) { if ($info['postby'] === $name_get) $parents[$i] = $info; } } // The status filtering ... if ($status_get !='all') { $res = $parents; $parents = array(); foreach($res as $i=>$info) { if ($info['status'] === $status_get) $parents[$i] = $info; } } // ------------- CREATING THE DISPLAY TABLE FROM $parents ARRAY... $out .= "\n\t"; $out .= "\n\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; if ($this->IsAdmin($this->GetUser())) { $out .= "\n\t\t"; } $out .= "\n\t\n\t"; if (count($parents) > 0) { foreach($parents as $i=>$data) { $out .= "\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; $out .= "\n\t\t"; if ($this->IsAdmin($this->GetUser())) { $st = array( 'Rejected' => 0, 'Implemented' => 0, 'Pending' => 0); $st[GetStatusStr($data['status'])] = 1; $out .= "\n\t\t"; } } else { $out .= "
".((($_GET['sort_up']==1||$_GET['sort_up']==-1) && ($sort_get =='title') )? (($sort_get_up==-1)? "⇓" : "⇑"):'')."Href("","", "phase=manage_sugs&sort=title&sort_up=".(-$sort_get_up))."\">Topic".((($_GET['sort_up']==1||$_GET['sort_up']==-1) && ($sort_get =='status') )? (($sort_get_up==-1)? "⇓" : "⇑"):'')."Href("","", "phase=manage_sugs&sort=status&sort_up=".(-$sort_get_up))."\">Status".((($_GET['sort_up']==1||$_GET['sort_up']==-1) && ($sort_get =='postby') )? (($sort_get_up==-1)? "⇓" : "⇑"):'')."Href("","", "phase=manage_sugs&sort=postby&sort_up=".(-$sort_get_up))."\">Author".((($_GET['sort_up']==1||$_GET['sort_up']==-1) && ($sort_get =='time') )? (($sort_get_up==-1)? "⇓" : "⇑"):'')."Href("","", "phase=manage_sugs&sort=time&sort_up=".(-$sort_get_up))."\">Posted On".((($_GET['sort_up']==1||$_GET['sort_up']==-1) && ($sort_get =='replies') )? (($sort_get_up==-1)? "⇓" : "⇑"):'')."Href("","", "phase=manage_sugs&sort=replies&sort_up=".(-$sort_get_up))."\">RepliesActions
Href("","", "phase=show_sug&id=".$data['id'])."\">".$data['title']."".GetStatusStr($data['status'])."".$this->Format($data['postby'])."".$data['time']."".$data['replies'].""; $out .= "\n\t\t
config["base_url"].$this->PageTitle().( ($this->config["rewrite_mode"]) ? "?" : "&")."\" method=\"get\">\n"; $out .= "\n\t\t\tHref("","","phase=del_sug&delid=".$data['id'])."\">Delete |"; $out .= "\n\t\t\tPageTitle()."\"/>"; $out .= "\n\t\t\t"; $out .= "\n\t\t\t"; $out .= "\n\t\t\t"; $out .= "\n\t\t\tChange to \n"; $out .= "\n\t\t\t"; $out .= "\n\t\t
"; } $out .= "\n\t\t
\n\t".$this->Format("--- @@//===No Matches===//@@ --- "); } } else { $out = ""; if ( $this->HasAccess("comment") || $this->HasAccess("write") || $this->IsAdmin() ) { $out .="
No Suggestions yet ...
Href("","", "phase=add_sug")."\">Add Suggestion Thread"; } $out .="
"; } echo $this->ReturnSafeHTML($out); } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- DISPLAY A SUGGESTION THREAD ** --------------------------------------------------------------------------------------------------------------------------------- */ elseif ($phase == 'show_sug') { $id = $_GET['id']+0; $sug_arr = GetAllSuggestions($all_sugs); $sug_arr = $sug_arr[$id]; $st = array( 'Rejected' => 0, 'Implemented' => 0, 'Pending' => 0); $st[GetStatusStr($sug_arr[0]['status'])] = 1; $out = $this->Format("====".$sug_arr[0]['title']."==== //The proposed suggestion is ".GetStatusStr($sug_arr[0]['status'])."//"); $out .= "\n\t\t
config["base_url"].$this->PageTitle().( ($this->config["rewrite_mode"]) ? "?" : "&")."\" method=\"get\">\n"; $out .= "Href("","", "phase=manage_sugs&sort=all\"").">Suggestions Index | "; $out .= "Href("","", "&phase=add_sug\"").">New Suggestion | "; $out .= "\n\t\t\tHref("","","phase=del_sug&delid=".$id)."\">Delete This Suggestion Thread |"; $out .= "\n\t\t\tPageTitle()."\"/>"; $out .= "\n\t\t\t"; $out .= "\n\t\t\t"; $out .= "\n\t\t\t"; $out .= "\n\t\t\tChange Status to \n"; $out .= "\n\t\t\t"; $out .= "\n\t\t
"; $out.= $this->Format("----"); foreach($sug_arr as $i => $data) { $out .= "\n"; $out .= "\n\t\n\t\t\n\t"; $out .= "\n\t\n\t\t\n\t\t\n\t"; // do the final row on this particular suggestion entry ... $out .= "\n\t\n\t\t\n\t"; $out .= "\n
".($this->Format("**".$data['title']."**")); // if this is the owner and this isnt a first suggestion , or this is an admin .. then add a delete button ... if (!$data['parent']==0) { if ( ($this->GetUserName() == $data['postby']) || ($this->IsAdmin($this->GetUser())) ) { $out .= " | Href("","", "&phase=del_sug&id=".$id."&delid=".$data['id'])."&title=".htmlspecialchars($data['title'])."\">Delete"; } } $out .= "\n\t\t
".($this->Format($data['content']))."
".($this->Format("//".$data['postby']." posted on ".$data['time']."//"))."
\n
"; } if ( ( ($this->HasAccess("comment")) && ($this->HasAccess("write")) )|| $this->IsAdmin()) { $out .= "
Href("","", "phase=reply_to&id=".$id)."\" method=\"post\">\n"; $out .= ""; $out .= "\n\tTopic :

"; $out .= "\n\t
"; $out .= "\n\t\t
When you are ready to submit your Reply you may press ".$this->Format("#%Alt#%+#%A#%")." or \n\t"; $out .= $this->FormClose(); } echo $this->ReturnSafeHTML($out); } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- DELETE REPLY ** --------------------------------------------------------------------------------------------------------------------------------- */ elseif ($phase == 'del_sug') { if ( isset($_GET['delid']) && ($_GET['delid'] != "") ) { if ( ($this->GetUserName() == $data['postby']) || ($this->IsAdmin($this->GetUser())) ) { $delid = $_GET['delid']; $parent_id = $_GET['id']; if ( ($delid == $parent_id) && ($this->IsAdmin($this->GetUser())) ) { $msg = "The thread entitled : ".$_GET['title']." was deleted"; $url = "&phase=show_sug&id=".$parent_id; } else { $msg = "The reply to the ".( (isset($_GET['title'])) ? $_GET['title'] : 'suggestion')." was deleted."; $url = "phase=manage_sugs"; } $this->Query("DELETE FROM ".$this->config["table_prefix"]."suggestions WHERE (id = '".$delid."' or parent='".$delid."')"); $this->SetMessage($msg); $this->Redirect($this->Href("","", $url)); } } else { $this->Redirect($this->Href("","", "&phase=show_sug&id=".$_GET['id'])); } } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- REPLY TO SUGGESTION ** --------------------------------------------------------------------------------------------------------------------------------- */ elseif ($phase == 'reply_to') { if ( ( ($this->HasAccess("comment")) && ($this->HasAccess("write")) )|| $this->IsAdmin()) { if (($_POST['status'] != "I") && ($_POST['status'] != "R")) { $this->Query("INSERT INTO ".$this->config["table_prefix"]."suggestions (title,postby,time,status,content,parent) ". "VALUES ('".addslashes($_POST['topic'])."', '".($this->GetUserName())."', NOW(), '".$_POST['status']."', '".addslashes($_POST['body'])."', '".$_GET['id']."')"); $this->SetMessage("The reply to the \"".( (isset($_GET['title'])) ? $_GET['title'] : 'suggestion')."\" was added." ); $this->Redirect($this->Href("","", "&phase=show_sug&id=".$_GET['id'])); } else { $this->SetMessage("You can't add replies to this suggestion. Its status is set to ".GetStatusStr($sug_arr['status'])); $this->Redirect($this->Href("","", "&phase=show_sug&id=".$_GET['id'])); } } else { $this->SetMessage("You can't add replies to this suggestion, you dont have the proper privileges."); $this->Redirect($this->Href("","", "&phase=show_sug&id=".$_GET['id'])); } } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- ADD NEW SUGGESTION THREAD ** --------------------------------------------------------------------------------------------------------------------------------- */ elseif ($phase == 'add_sug') { if ( ( ($this->HasAccess("comment")) && ($this->HasAccess("write")) )|| $this->IsAdmin()) { if (!isset($_GET['done'])) { $out = $this->Format("@@===New Suggestion===@@"); $out .= "Href("","", "phase=manage_sugs&sort=all")."\">Suggestions Index"; $out .= $this->Format(">>Minimum **Topic** length is set to ".$min_topic_length." character".(($min_topic_length == 1)? '' : 's')." --- Minimum **Reply** length is set to ".$min_reply_length." character".(($min_reply_length == 1)? '' : 's').">>--- ----"); $out .= "Href("","", "phase=add_sug&done=1")."\" method=\"post\">\n"; $out .= "\n\tTopic :

"; $out .= "\n\t
"; $out .= "\n\t\t
When you are ready to submit your Reply you may press ".$this->Format("#%Alt#%+#%A#%")." or \n\t"; $out .= $this->FormClose(); echo $this->ReturnSafeHTML($out); } else { if (isset($_GET['done']) )// if the Add Reply was pressed then { // check if the lengths of the inputs are ok ... $_GET['done'] = ( (strlen($_POST['topic']) >= $min_topic_length)&&(strlen($_POST['body_text']) >= $min_reply_length) )? 1 : -1; } else // if we reached here from smwh else than the Add Reply Button. .. (possibly a $this->Redirect) { $_GET['done'] = 0; } switch($_GET['done']) { case 1: $this->Query("INSERT INTO ".$this->config['table_prefix']."suggestions( `title` , `postby` , `time` , `content` , `parent` ) VALUES ( '".addslashes($_POST['topic'])."', '".($this->GetUserName())."', now( ) , '".addslashes($_POST['body_text'])."', 0)"); $_GET['done'] = 0; $this->SetMessage("New Suggestion Posted"); $this->Redirect($this->Href("","", "phase=manage_sug")); break; case -1: $msg = "The Suggestion Topic has to be more than ".$min_topic_length." character".(($min_topic_length == 1 )?'s' : '')." long and "; $msg .= "the Suggestion Text has to be more than ".$min_reply_length." character".(($min_reply_length == 1 )?'s' : '')." long."; $this->SetMessage($msg); $this->Redirect($this->Href("","", "&phase=add_sug")); break; default: $this->Redirect($this->Href("","", "&phase=add_sug")); } } } } /* ** --------------------------------------------------------------------------------------------------------------------------------- ** ------------------------------------------------------------------------------- CHANGE STATUS TO A SUGGESTION THREAD ** --------------------------------------------------------------------------------------------------------------------------------- */ elseif ($phase == 'chng_status') { if ( ($this->IsAdmin()) && ($_GET['t_id'] !== 0) ) { $this->Query("UPDATE ".$this->config['table_prefix']."suggestions SET status='".$_GET['sug_status']."' where id=".$_GET['t_id']." or parent=".$_GET['t_id']); $this->SetMessage("The status of ".GetTitleFromID($_GET['t_id'], $all_sugs)." is now set to ".GetStatusStr($_GET['sug_status'])); $this->Redirect($this->Href("","",( ($_GET['from_phase']=='show_sug') ? "&phase=".$_GET['from_phase']."&id=".$_GET['t_id'] : "phase=".$_GET['from_phase'] ) )); } else // silently redirect to the Suggestions Index ... { $this->Redirect($this-Href("","","phase=manage_sugs")); } } ?> %% ===Usage=== You just insert ""{{msgboard}}"" inside any page. Keep in mind that posting on this is affected by the ACLS of the specific page. ===Final Note=== This is my Gift to the Wikka development to enable these wonderfull people behind Wikka to manage the Suggestions they receive ... Happy New Year to All ;) ----//Suggestions, Modifications as well as comments are most welcome ...//---- Happy New Year to all! - ++See my comment below for the missing "create entry function"++ I added a little bit to the code above. It should be possible now to add new topics if there are none - I added a ".$this->config["table_prefix"]." to the first query - changing the status of a topic does not work with mod_rewrite - I like this modification very much :) --NilsLindenberg ---- CategoryUserContributions