Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

jun09 branch

  • Loading branch information...
commit 345fb8030fe0835cd658767c2b32d426159ed1d9 1 parent 0eb47e5
Jeff Reifman authored
Showing with 11,532 additions and 0 deletions.
  1. +178 −0 core/classes/forum.class.php
  2. +244 −0 core/classes/researchSurveyMonkey.class.php
  3. +1 −0  core/classes/subscriptions.class.php
  4. +31 −0 docs/approvedClouds.txt
  5. +38 −0 facebook/classes/autoPost.class.php
  6. +92 −0 facebook/pages/pageWall.class.php
  7. +32 −0 facebook/scripts/autoPost.js
  8. +29 −0 open-social-media-toolkit.tmproj
  9. +96 −0 php/console/controllers/admin_controller.php
  10. +75 −0 php/console/controllers/app_controller.php
  11. +90 −0 php/console/controllers/dashpods_controller.php
  12. +75 −0 php/console/controllers/facebook_controller.php
  13. +48 −0 php/console/controllers/main_controller.php
  14. +657 −0 php/console/controllers/members_controller.php
  15. +127 −0 php/console/controllers/settings_controller.php
  16. +15 −0 php/console/controllers/statistics_controller.php
  17. +606 −0 php/console/controllers/stories_controller.php
  18. +690 −0 php/console/controllers/street_team_controller.php
  19. +96 −0 php/console/filters.php
  20. +81 −0 php/console/helpers/application_helper.php
  21. BIN  php/console/images/banner.jpg
  22. BIN  php/console/loading_bar.gif
  23. +75 −0 php/console/models/BaseModel.php
  24. +15 −0 php/console/models/Log.php
  25. +15 −0 php/console/models/LogDumps.php
  26. +14 −0 php/console/models/OutboundMessages.php
  27. +14 −0 php/console/models/RawExtLinks.php
  28. +14 −0 php/console/models/SessionLengths.php
  29. +60 −0 php/console/models/Songs.php
  30. +14 −0 php/console/models/User.php
  31. +14 −0 php/console/models/UserInfo.php
  32. +40 −0 php/console/models/leads.php
  33. +1,594 −0 php/console/pods.js
  34. +112 −0 php/console/pods/ActionStats.php
  35. +104 −0 php/console/pods/AgeDistribution.php
  36. +184 −0 php/console/pods/BasePod.php
  37. +55 −0 php/console/pods/ChallengeChart.php
  38. +211 −0 php/console/pods/ChallengeReport.php
  39. +99 −0 php/console/pods/CityDistribution.php
  40. +81 −0 php/console/pods/CountryDistribution.php
  41. +85 −0 php/console/pods/EmailDistribution.php
  42. +85 −0 php/console/pods/GenderDistribution.php
  43. +75 −0 php/console/pods/InterestDistribution.php
  44. +100 −0 php/console/pods/MemberStats.php
  45. +92 −0 php/console/pods/MostDiscussedStories.php
  46. +91 −0 php/console/pods/MostReadStories.php
  47. +92 −0 php/console/pods/MostShared.php
  48. +72 −0 php/console/pods/SessionLengths.php
  49. +102 −0 php/console/pods/SessionStats.php
  50. +99 −0 php/console/pods/StateDistribution.php
  51. +25 −0 php/console/pods/Statistics.php
  52. +220 −0 php/console/pods/StoryReport.php
  53. +139 −0 php/console/pods/TopRatedStories.php
  54. +73 −0 php/console/pods/TotalMembers.php
  55. +413 −0 php/console/pods/UserReport.php
  56. +35 −0 php/console/readme.txt
  57. +15 −0 php/console/readme_indexes.txt
  58. +157 −0 php/console/roles.php
  59. +204 −0 php/console/utility_functions.php
  60. +46 −0 php/console/views/admin/cronjobs.php
  61. +3 −0  php/console/views/admin/index.php
  62. 0  php/console/views/dashpods/base_page.php
  63. +12 −0 php/console/views/facebook/downloadsettings.php
  64. +3 −0  php/console/views/facebook/index.php
  65. +43 −0 php/console/views/main/dashboard.php
  66. +6 −0 php/console/views/members/fields_forumtopic.php
  67. +42 −0 php/console/views/members/forumtopics.php
  68. +3 −0  php/console/views/members/index.php
  69. +38 −0 php/console/views/members/member_emails.php
  70. +75 −0 php/console/views/members/member_fields.php
  71. +61 −0 php/console/views/members/members.php
  72. +15 −0 php/console/views/members/modify_forumtopic.php
  73. +15 −0 php/console/views/members/modify_member.php
  74. +15 −0 php/console/views/members/modify_outboundmessage.php
  75. +13 −0 php/console/views/members/new_forumtopic.php
  76. +13 −0 php/console/views/members/new_member.php
  77. +13 −0 php/console/views/members/new_outboundmessage.php
  78. +59 −0 php/console/views/members/outboundmessage_fields.php
  79. +52 −0 php/console/views/members/outboundmessages.php
  80. +10 −0 php/console/views/members/send_outboundmessage.php
  81. +43 −0 php/console/views/members/show_friend_invite_credits.php
  82. +17 −0 php/console/views/members/view_forumtopic.php
  83. +252 −0 php/console/views/members/view_member.php
  84. +21 −0 php/console/views/members/view_member_email.php
  85. +61 −0 php/console/views/members/view_outboundmessage.php
  86. 0  php/console/views/pod.php
  87. +3 −0  php/console/views/settings/index.php
  88. +173 −0 php/console/views/settings/initialize_tables.php
  89. 0  php/console/views/settings/load_settings.php
  90. +46 −0 php/console/views/settings/new_pod.php
  91. +69 −0 php/console/views/statistics/base.php
  92. +3 −0  php/console/views/statistics/index.php
  93. +28 −0 php/console/views/stories/add_story_widget.php
  94. +27 −0 php/console/views/stories/comment_fields.php
  95. +45 −0 php/console/views/stories/comments.php
  96. +15 −0 php/console/views/stories/modify_comment.php
  97. +15 −0 php/console/views/stories/modify_story.php
  98. +15 −0 php/console/views/stories/modify_video.php
  99. +15 −0 php/console/views/stories/modify_widget.php
  100. +13 −0 php/console/views/stories/new_comment.php
  101. +13 −0 php/console/views/stories/new_story.php
  102. +13 −0 php/console/views/stories/new_video.php
  103. +13 −0 php/console/views/stories/new_widget.php
  104. +24 −0 php/console/views/stories/place_widget.php
  105. +52 −0 php/console/views/stories/story_fields.php
  106. +43 −0 php/console/views/stories/story_posts.php
  107. +8 −0 php/console/views/stories/video_fields.php
  108. +38 −0 php/console/views/stories/video_posts.php
  109. +39 −0 php/console/views/stories/view_comment.php
  110. +91 −0 php/console/views/stories/view_story.php
  111. +24 −0 php/console/views/stories/view_video.php
  112. +42 −0 php/console/views/stories/view_widget.php
  113. +55 −0 php/console/views/stories/widget_fields.php
  114. +53 −0 php/console/views/stories/widgets.php
  115. +56 −0 php/console/views/street_team/assign_prize.php
  116. +288 −0 php/console/views/street_team/award_prize.php
  117. +78 −0 php/console/views/street_team/challenge_detail_report.php
  118. +89 −0 php/console/views/street_team/challenge_fields.php
  119. +60 −0 php/console/views/street_team/challenges.php
  120. +39 −0 php/console/views/street_team/completed_challenge_fields.php
  121. +57 −0 php/console/views/street_team/completed_challenges.php
  122. +3 −0  php/console/views/street_team/index.php
  123. +78 −0 php/console/views/street_team/leaders.php
  124. +14 −0 php/console/views/street_team/modify_challenge.php
  125. +15 −0 php/console/views/street_team/modify_completed_challenge.php
  126. +15 −0 php/console/views/street_team/modify_order.php
  127. +14 −0 php/console/views/street_team/modify_prize.php
  128. +13 −0 php/console/views/street_team/new_challenge.php
  129. +13 −0 php/console/views/street_team/new_completed_challenge.php
  130. +13 −0 php/console/views/street_team/new_order.php
  131. +13 −0 php/console/views/street_team/new_prize.php
  132. +74 −0 php/console/views/street_team/order_fields.php
  133. +62 −0 php/console/views/street_team/orders.php
  134. +104 −0 php/console/views/street_team/prize_fields.php
  135. +67 −0 php/console/views/street_team/prizes.php
  136. +41 −0 php/console/views/street_team/view_challenge.php
  137. +134 −0 php/console/views/street_team/view_completed_challenge.php
  138. +35 −0 php/console/views/street_team/view_order.php
  139. +47 −0 php/console/views/street_team/view_prize.php
  140. +14 −0 sites/climate/facebook/templates/forum.php
View
178 core/classes/forum.class.php
@@ -0,0 +1,178 @@
+<?php
+
+// to do - UserForumTopics table
+// topic id, last visit
+// code to get topic list table for a specific user showing new posts since last visit
+
+require_once(PATH_CORE.'/classes/dbRowObject.class.php');
+class ForumTopics extends dbRowObject
+{
+
+}
+
+class ForumTopicsTable
+{
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ // standard table fields
+ var $db;
+ static $tablename="ForumTopics";
+ static $idname = "id";
+ static $idtype = "INT(11) unsigned NOT NULL auto_increment";
+ static $dbRowObjectClass = "ForumTopics";
+
+ static $fields = array(
+ "title" => "VARCHAR(255) default ''",
+ "intro" => "TEXT default ''",
+ "lastChanged" => "DATETIME",
+ "numPostsToday" => "INT(4) default 0",
+ "numViewsToday" => "INT(4) default 0"
+ );
+
+ static $keydefinitions = array();
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ // standard table functions
+ function __construct(&$db=NULL)
+ {
+ if (is_null($db))
+ {
+ require_once('db.class.php');
+ $this->db=new cloudDatabase();
+ } else
+ $this->db=$db;
+ }
+ // although many functions will be duplicated between table subclasses, having a parent class gets too messy
+ function getRowObject()
+ {
+ $classname = self::$dbRowObjectClass;
+ return new $classname($this->db, self::$tablename, array_keys(self::$fields), self::$idname);
+ }
+
+ // generic table creation routine, same for all *Table classes
+ static function createTable($manageObj)
+ {
+ $manageObj->addTable(self::$tablename,self::$idname,self::$idtype,"MyISAM");
+ foreach (array_keys(self::$fields) as $key)
+ {
+ $manageObj->updateAddColumn(self::$tablename,$key,self::$fields[$key]);
+ }
+ foreach (self::$keydefinitions as $keydef)
+ {
+ $manageObj->updateAddKey(self::$tablename,$keydef[0], $keydef[1], $keydef[2], $keydef[3]);
+ }
+ }
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ function testPopulate()
+ {
+
+ $Forum = $this->getRowObject();
+ $Forum->title = 'Rescue a cute animal from a politically incorrect predicament';
+ $Forum->pointValue = 100;
+ $Forum->dateStart = date('Y-m-d H:i:s', time());
+ if (!self::checkForumExistsByTitle($Forum->title)) $Forum->insert();
+
+ }
+
+
+ function checkForumExistsByTitle($title)
+ {
+
+ $chkDup=$this->db->queryC("SELECT ".self::$idname." FROM ".self::$tablename." WHERE title='$title'");
+ return $chkDup;
+
+ }
+
+};
+
+class Forums {
+
+ var $db;
+ var $templateObj;
+
+ function __construct(&$db=NULL)
+ {
+ if (is_null($db)) {
+ require_once('db.class.php');
+ $this->db=new cloudDatabase();
+ } else
+ $this->db=$db;
+ $this->setupLibraries();
+
+ }
+
+ function loadAndTouchForumTopic($id=0) {
+ $this->touchForumTopic($id);
+ $ftTable = new ForumTopicsTable($this->db);
+ $ft = $ftTable->getRowObject();
+ $ft->load($id);
+ return $ft;
+ }
+
+ function touchForumTopic($id=0) {
+ $this->db->update("ForumTopics","numViewsToday=numViewsToday+1","id=$id");
+ }
+
+ function setupLibraries() {
+ require_once(PATH_CORE.'/classes/template.class.php');
+ $this->templateObj=new template($this->db);
+ $this->templateObj->registerTemplates(MODULE_ACTIVE,'Forums');
+ }
+
+ function fetchForumList($sort, $currentPage=1)
+ {
+
+ $cacheName='chList_'.$sort.'_'.$currentPage;
+ if ($this->templateObj->checkCache($cacheName,15)) {
+ // still current, get from cache
+ $code=$this->templateObj->fetchCache($cacheName);
+ } else {
+ // to do - take out rows per page
+
+ $where= "WHERE status='enabled'";
+
+ if ($sort=='isFeatured')
+ $where.=' AND isFeatured=1';
+
+ if ($sort =='pointValue')
+ $sort = "$sort DESC";
+
+ $code='';
+ $rowsPerPage = 2*ROWS_PER_PAGE;
+ $startRow=($currentPage-1)*$rowsPerPage; // replace rows per page
+ $ForumList=$this->templateObj->db->query(
+ "SELECT SQL_CALC_FOUND_ROWS
+ thumbnail, title, pointValue, id,
+ MONTHNAME(dateStart) AS monthstart,
+ DAY(dateStart) AS daystart,
+ MONTHNAME(dateEnd) AS monthend,
+ DAY(dateEnd) AS dayend,description,
+ (CASE type WHEN 'automatic' THEN 'hidden'
+ WHEN 'submission' THEN ''
+ END) AS submissionStyle
+ FROM Forums $where ORDER BY type DESC, $sort LIMIT $startRow,".$rowsPerPage.";");
+
+ // to do - later we'll move these template defs
+ if ($this->templateObj->db->countQ($ForumList)>0)
+ {
+ $rowTotal=$this->templateObj->db->countFoundRows();
+ $pagingHTML=$this->templateObj->paging($currentPage,$rowTotal,$rowsPerPage,'&p=Forums&currentPage='); // later put back page->rowsPerPage
+ // $this->templateObj->db->setTemplate`('comments', array($this, 'decodeComment'), 'comments');
+ $this->templateObj->db->setTemplateCallback('pointValue', array($this, 'getPointValue'), 'pointValue');
+ //$code.=$this->templateObj->mergeTemplate($this->templateObj->templates['commentList'],$this->templateObj->templates['commentItem']);
+ $code.=$pagingHTML;
+ $code.=$this->templateObj->mergeTemplate($this->templateObj->templates[ForumPanelList],$this->templateObj->templates[ForumPanelItem]);
+ $code.=$pagingHTML;
+ } else {
+ $code.='No Forums found.';
+ }
+
+ $this->templateObj->cacheContent($cacheName,$code);
+ }
+ return $code;
+
+ }
+
+}
+
+?>
View
244 core/classes/researchSurveyMonkey.class.php
@@ -0,0 +1,244 @@
+<?php
+require_once(PATH_CORE.'/classes/dbRowObject.class.php');
+
+class SurveyMonkey extends dbRowObject
+{
+
+};
+
+class SurveyMonkeyTable
+{
+
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ // standard table fields
+ var $db;
+ static $tablename="SurveyMonkeys";
+ static $idname = "id";
+ static $idtype = "INT(11) unsigned NOT NULL auto_increment";
+ static $dbRowObjectClass = "SurveyMonkey";
+
+ static $fields = array(
+ "email" => "VARCHAR(255) default ''",
+ "userid" => "BIGINT(20) unsigned default 0",
+ "siteid" => "BIGINT(20) unsigned default 0",
+ "q1a" => "TINYINT(1) default 0",
+ "q1b" => "TINYINT(1) default 0",
+ "q1c" => "TINYINT(1) default 0",
+ "q1d" => "TINYINT(1) default 0",
+ "q1e" => "TINYINT(1) default 0",
+ "q1f" => "TINYINT(1) default 0",
+ "q1g" => "TINYINT(1) default 0",
+ "q2a" => "TINYINT(1) default 0",
+ "q2b" => "TINYINT(1) default 0",
+ "q2c" => "TINYINT(1) default 0",
+ "q2d" => "TINYINT(1) default 0",
+ "q2e" => "TINYINT(1) default 0",
+ "q3a" => "TINYINT(1) default 0",
+ "q3b" => "TINYINT(1) default 0",
+ "q3c" => "TINYINT(1) default 0",
+ "q3d" => "TINYINT(1) default 0",
+ "q3e" => "TINYINT(1) default 0",
+ "q3f" => "TINYINT(1) default 0",
+ "q3g" => "TINYINT(1) default 0",
+ "q3h" => "TINYINT(1) default 0",
+ "q4a" => "TINYINT(1) default 0",
+ "q4b" => "TINYINT(1) default 0",
+ "q4c" => "TINYINT(1) default 0",
+ "q4d" => "TINYINT(1) default 0",
+ "q4e" => "TINYINT(1) default 0",
+ "q4f" => "TINYINT(1) default 0",
+ "q4g" => "TINYINT(1) default 0",
+ "q5a" => "TINYINT(1) default 0",
+ "q5b" => "TINYINT(1) default 0",
+ "q5c" => "TINYINT(1) default 0",
+ "q5d" => "TINYINT(1) default 0",
+ "q5e" => "TINYINT(1) default 0",
+ "q5f" => "TINYINT(1) default 0",
+ "q5g" => "TINYINT(1) default 0",
+ "q5h" => "TINYINT(1) default 0",
+ "q5i" => "TINYINT(1) default 0",
+ "q5j" => "TINYINT(1) default 0",
+ "q5k" => "TINYINT(1) default 0",
+ "q6" => "TINYINT(1) default 0",
+ "q7" => "TINYINT(1) default 0",
+ "q8a" => "TINYINT(1) default 0",
+ "q8b" => "TINYINT(1) default 0",
+ "q8c" => "TINYINT(1) default 0",
+ "q8d" => "TINYINT(1) default 0",
+ "q8e" => "TINYINT(1) default 0",
+ "q8f" => "TINYINT(1) default 0",
+ "q8g" => "TINYINT(1) default 0",
+ "q8h" => "TINYINT(1) default 0",
+ "q9a" => "TINYINT(1) default 0",
+ "q9b" => "TINYINT(1) default 0",
+ "q9c" => "TINYINT(1) default 0",
+ "q9d" => "TINYINT(1) default 0",
+ "q9e" => "TINYINT(1) default 0",
+ "q9f" => "TINYINT(1) default 0",
+ "q10a" => "TINYINT(1) default 0",
+ "q10b" => "TINYINT(1) default 0",
+ "q10c" => "TINYINT(1) default 0",
+ "q10d" => "TINYINT(1) default 0",
+ "q10e" => "TINYINT(1) default 0",
+ "q10f" => "TINYINT(1) default 0",
+ "q11a" => "TINYINT(1) default 0",
+ "q11b" => "TINYINT(1) default 0",
+ "q11c" => "TINYINT(1) default 0",
+ "q11d" => "TINYINT(1) default 0",
+ "q11e" => "TINYINT(1) default 0",
+ "q11f" => "TINYINT(1) default 0",
+ "q11g" => "TINYINT(1) default 0",
+ "q11h" => "TINYINT(1) default 0",
+ "q12a" => "TINYINT(1) default 0",
+ "q12b" => "TINYINT(1) default 0",
+ "q12c" => "TINYINT(1) default 0",
+ "q12d" => "TINYINT(1) default 0",
+ "q12e" => "TINYINT(1) default 0",
+ "q12f" => "TINYINT(1) default 0",
+ "q12g" => "TINYINT(1) default 0",
+ "q12h" => "TINYINT(1) default 0",
+ "q13a" => "TINYINT(1) default 0",
+ "q13b" => "TINYINT(1) default 0",
+ "q13c" => "TINYINT(1) default 0",
+ "q13d" => "TINYINT(1) default 0",
+ "q14a" => "TINYINT(1) default 0",
+ "q14b" => "TINYINT(1) default 0",
+ "q14c" => "TINYINT(1) default 0",
+ "q14d" => "TINYINT(1) default 0",
+ "q14e" => "TINYINT(1) default 0",
+ "q14f" => "TINYINT(1) default 0",
+ "q15" => "TINYINT(1) default 0",
+ "q16" => "TINYINT(1) default 0",
+ "q17a" => "TINYINT(1) default 0",
+ "q17b" => "TINYINT(1) default 0",
+ "q17c" => "TINYINT(1) default 0",
+ "q17d" => "TINYINT(1) default 0",
+ "q17e" => "TINYINT(1) default 0",
+ "q18" => "TINYINT(1) default 0",
+ "q19" => "TINYINT(1) default 0",
+ "q20" => "TINYINT(1) default 0",
+ "q21" => "TINYINT(1) default 0",
+ "q22" => "TINYINT(1) default 0",
+ "q23" => "TINYINT(1) default 0",
+ "q24" => "TINYINT(1) default 0",
+ "q25" => "TINYINT(1) default 0",
+ "q26" => "TINYINT(1) default 0",
+ "q27" => "TINYINT(1) default 0",
+ "q28a" => "TINYINT(1) default 0",
+ "q28b" => "TINYINT(1) default 0",
+ "q28c" => "TINYINT(1) default 0",
+ "q28d" => "TINYINT(1) default 0",
+ "q28e" => "TINYINT(1) default 0",
+ "q28f" => "TINYINT(1) default 0",
+ "q29" => "TINYINT(1) default 0",
+ "q30" => "TINYINT(1) default 0",
+ "q31" => "TINYINT(1) default 0",
+ "q32" => "TINYINT(1) default 0",
+ "q33" => "TINYINT(1) default 0",
+ "q34" => "TINYINT(1) default 0",
+ "q35" => "TINYINT(1) default 0",
+ "q36" => "TINYINT(1) default 0",
+ "q37" => "TINYINT(1) default 0",
+ "q38a" => "TINYINT(1) default 0",
+ "q38b" => "TINYINT(1) default 0",
+ "q38c" => "TINYINT(1) default 0",
+ "q38d" => "TINYINT(1) default 0",
+ "q38e" => "TINYINT(1) default 0"
+ );
+
+ static $keydefinitions = array();
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+ // standard table functions
+ function __construct(&$db=NULL)
+ {
+ if (is_null($db))
+ {
+ require_once('db.class.php');
+ $this->db=new cloudDatabase();
+ } else
+ $this->db=$db;
+
+ $this->db->selectDB('research');
+ }
+ // although many functions will be duplicated between table subclasses, having a parent class gets too messy
+ function getRowObject()
+ {
+ $classname = self::$dbRowObjectClass;
+ return new $classname($this->db, self::$tablename, array_keys(self::$fields), self::$idname);
+ }
+
+ // generic table creation routine, same for all *Table classes
+ static function createTable($manageObj)
+ {
+ $manageObj->addTable(self::$tablename,self::$idname,self::$idtype,"MyISAM");
+ foreach (array_keys(self::$fields) as $key)
+ {
+ $manageObj->updateAddColumn(self::$tablename,$key,self::$fields[$key]);
+ }
+ foreach (self::$keydefinitions as $keydef)
+ {
+ $manageObj->updateAddKey(self::$tablename,$keydef[0], $keydef[1], $keydef[2], $keydef[3]);
+ }
+
+ }
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ function loadCSV() {
+ ini_set('auto_detect_line_endings',TRUE);
+ $CSV_FILE = PATH_CONSOLE.'/survey_monkey.csv';
+ $SITE_ID = 1;
+ $COL_COUNT = 124;
+
+ $insert_sql = "REPLACE INTO SurveyMonkeys (email,userid,siteid,q1a,q1b,q1c,q1d,q1e,q1f,q1g,q2a,q2b,q2c,q2d,q2e,q3a,q3b,q3c,q3d,q3e,q3f,q3g,q3h,q4a,q4b,q4c,q4d,q4e,q4f,q4g,q5a,q5b,q5c,q5d,q5e,q5f,q5g,q5h,q5i,q5j,q5k,q6,q7,q8a,q8b,q8c,q8d,q8e,q8f,q8g,q8h,q9a,q9b,q9c,q9d,q9e,q9f,q10a,q10b,q10c,q10d,q10e,q10f,q11a,q11b,q11c,q11d,q11e,q11f,q11g,q11h,q12a,q12b,q12c,q12d,q12e,q12f,q12g,q12h,q13a,q13b,q13c,q13d,q14a,q14b,q14c,q14d,q14e,q14f,q15,q16,q17a,q17b,q17c,q17d,q17e,q18,q19,q20,q21,q22,q23,q24,q25,q26,q27,q28a,q28b,q28c,q28d,q28e,q28f,q29,q30,q31,q32,q33,q34,q35,q36,q37,q38a,q38b,q38c,q38d,q38e) VALUES ";
+
+ $row = 1;
+ $error = '';
+ $handle = fopen($CSV_FILE, "r");
+ while (($data = fgetcsv($handle, 0, ",")) !== FALSE) {
+ if ($row == 1) {
+ $row++;
+ continue;
+ }
+ $email = $data[0];
+ $user_sql = "SELECT userid FROM UserCollectives WHERE email = '$email' AND siteid = $SITE_ID";
+ $res = $this->db->queryC($user_sql);
+ if (!$res) {
+ $error .= "{Couldn't find userid with email: $email}";
+ continue;
+ } else {
+ $res = $this->db->readQ($res);
+ }
+ $userid = $res->userid;
+
+ $num = count($data);
+ //echo "<p> $num fields in line $row: <br /></p>\n";
+ $row++;
+ $value_str = "('$email', '$userid', '$SITE_ID',";
+ //for ($c=1; $c < $num; $c++) {
+ for ($c=1; $c < $COL_COUNT; $c++) {
+ if (isset($data[$c]))
+ $val = mysql_real_escape_string($data[$c]);
+ else
+ $val = 0;
+
+ $value_str .= "'$val',";
+ }
+ $value_str = substr($value_str, 0, -1);
+ $value_str .= '),';
+ $insert_sql .= $value_str;
+ //echo $data[$c] . "<br />\n";
+ }
+ fclose($handle);
+ if ($row > 1) {
+ $insert_sql = substr($insert_sql, 0, -1);
+ $this->db->query($insert_sql);
+
+ return "Inserted ".($row-1)." surveys.(Error: $error)";
+ } else {
+ return "ERROR:: Failed to insert survey data..(Error: $error)";
+ }
+ }
+
+};
+
+?>
View
1  core/classes/subscriptions.class.php
@@ -0,0 +1 @@
+<?php
View
31 docs/approvedClouds.txt
@@ -0,0 +1,31 @@
+CloudId - Name
+77 2008 Elections
+70 CIA Leak Case
+87 Darfur
+159 Food
+73 Global Warming
+156 Green Energy
+68 Iraq
+101 Israel Palestine
+158 Living with Cancer
+75 Media Reform
+198 Online community
+157 Open Society
+160 Reproductive Rights
+136 The Daily Show
+155 Two Americas
+388 Sarah Palin
+172 Seattle
+107 Technology
+108 Environment
+109 Health
+110 Sports
+111 Spirituality
+114 World
+115 U.S.
+116 Business
+117 Opinion
+118 Science
+119 Arts
+120 Entertainment
+121 Oddities
View
38 facebook/classes/autoPost.class.php
@@ -0,0 +1,38 @@
+<?php
+/*
+ * autoPost class support
+
+provides supportive functions for autoposting behavior, for quick posting by moderators and such
+called from ajax requests mostly
+
+ */
+
+class autoPost
+{
+ var $app;
+ var $session;
+ var $db;
+ var $facebook;
+
+ function __construct(&$app=NULL)
+ {
+ if (!is_null($app)) {
+ $this->app=&$app;
+ $this->session=&$app->session;
+ $this->facebook = &$app->session->facebook;
+ $this->db=&$app->db;
+ }
+ }
+
+ function fetchPostForm($id=0) {
+ // fetch story info
+ $q=$this->db->query("SELECT * FROM Newswire WHERE id=$id;");
+ $story=$this->db->readQ($q);
+ // send form with title and caption
+ $code.='<p>Title: <br /><input type="text" name="title" id="title_'.$id.'" value="'.$story->title.'" /></p>';
+ $code.='<p>Caption: <br /><textarea name="caption" id="caption_'.$id.'" class="formfield" id="caption" cols="80" rows="8">'.strip_tags($story->caption).'</textarea></p>';
+ $code.='<p><input type="button" name="submit" value="Submit" onclick="postPublish('.$id.');" /><a href="#" onclick="hidePreviewPublish('.$id.');return false;">Cancel</a></p>';
+ return $code;
+ }
+}
+?>
View
92 facebook/pages/pageWall.class.php
@@ -0,0 +1,92 @@
+<?php
+
+/* Provides Facebook-client specific action team help */
+class pageWall {
+
+ var $page;
+ var $db;
+ var $session;
+ var $teamObj;
+ var $templateObj;
+ var $utilObj;
+ var $forumObj;
+ var $isAppTab=false;
+
+ function __construct(&$page) {
+ $this->page=&$page;
+ $this->db=&$page->db;
+ $this->facebook=&$page->facebook;
+ $this->setupLibraries();
+ }
+
+ function setupLibraries() {
+ require_once(PATH_CORE.'/classes/template.class.php');
+ $this->templateObj=new template($this->db);
+ $this->templateObj->registerTemplates(MODULE_ACTIVE,'teamactivity');
+ $this->templateObj->registerTemplates(MODULE_ACTIVE,'forum');
+ require_once(PATH_CORE.'/classes/utilities.class.php');
+ $this->utilObj=new utilities($this->db);
+ require_once(PATH_FACEBOOK.'/classes/actionTeam.class.php');
+ $this->teamObj=new actionTeam($this->page);
+ require_once(PATH_CORE.'/classes/forum.class.php');
+ $this->forumObj=new Forums($this->db);
+ }
+
+ function fetchConversation($topic=0) {
+ // to do
+ // increment views
+ // add last viewed by user to UserForumHistory
+ $ft=$this->forumObj->loadAndTouchForumTopic($topic);
+ $inside.='<div id="col_left"><!-- begin left side -->';
+ $inside.='<h5><a href="?p=wall">Topics &raquo;</a> '.$ft->title.'</h5>';
+ if ($ft->intro<>'') {
+ $inside.='<p>'.$ft->intro.'</p>';
+ }
+ $inside.='<fb:comments xid="'.CACHE_PREFIX.'_wall_'.$topic.'" canpost="true" candelete="true" numposts="25" callbackurl="'.URL_CALLBACK.'?p=ajax&m=wall&topic='.$topic.'"></fb:comments>';
+ $inside.='</div><!-- end left side --><div id="col_right">';
+ $inside.=$this->teamObj->fetchSidePanel('leaders');
+ $inside.='</div> <!-- end right side -->';
+// if ($mode=='teamWrap') return $inside;
+// $inside=$tabs.'<div id="teamWrap">'.$inside.'<!-- end teamWrap --></div>';
+ if ($this->page->isAjax) return $inside;
+ $code=$this->page->constructPage('wall',$inside);
+ return $code;
+ }
+
+ function fetchTopics ($mode='',$option='') {
+ $inside.='<div id="col_left"><!-- begin left side -->';
+ $this->templateObj->db->result=$this->templateObj->db->query("SELECT * FROM ForumTopics ORDER BY title ASC;");
+ $this->templateObj->db->setTemplateCallback('lastChanged', array($this->utilObj, 'time_since'), 'lastChanged');
+ $inside.=$this->templateObj->mergeTemplate($this->templateObj->templates['forumTopicsList'],$this->templateObj->templates['forumTopicsListItem']);
+ $inside.='</div><!-- end left side --><div id="col_right">';
+ $inside.=$this->teamObj->fetchSidePanel('leaders');
+ $inside.='</div> <!-- end right side -->';
+// if ($mode=='teamWrap') return $inside;
+// $inside=$tabs.'<div id="teamWrap">'.$inside.'<!-- end teamWrap --></div>';
+ if ($this->page->isAjax) return $inside;
+ $code=$this->page->constructPage('wall',$inside);
+ return $code;
+ }
+
+ function fetch($mode='fullPage',$option='alltime') {
+ if (CACHE_PREFIX=='sea' OR CACHE_PREFIX=='hd') {
+ if (isset($_GET['topic'])) {
+ return $this->fetchConversation($_GET['topic']);
+ } else
+ return $this->fetchTopics($mode='fullPage',$option='alltime');
+ }
+ $tabs.=$this->teamObj->buildSubNav('wall');
+ $inside.='<div id="col_left"><!-- begin left side -->';
+ $inside.='<fb:comments xid="'.CACHE_PREFIX.'_wall" canpost="true" candelete="true" numposts="25" callbackurl="'.URL_CALLBACK.'?p=ajax&m=wall"></fb:comments>';
+ $inside.='</div><!-- end left side --><div id="col_right">';
+ $inside.=$this->teamObj->fetchSidePanel('leaders');
+ $inside.='</div> <!-- end right side -->';
+ if ($mode=='teamWrap') return $inside;
+ $inside=$tabs.'<div id="teamWrap">'.$inside.'<!-- end teamWrap --></div>';
+ if ($this->page->isAjax) return $inside;
+ $code=$this->page->constructPage('team',$inside);
+ return $code;
+ }
+
+}
+?>
View
32 facebook/scripts/autoPost.js
@@ -0,0 +1,32 @@
+function previewPublish(id) {
+ lookupSession();
+ var ajax = new Ajax();
+ ajax.responseType = Ajax.FBML;
+ ajax.requireLogin = true;
+ ajax.ondone = function(transport) {
+ document.getElementById('prePub_'+id).setInnerFBML(transport);
+ document.getElementById('prePub_'+id).toggleClassName('hidden');
+ }
+ ajax.post(ajaxUrl+"?p=ajax&m=previewPublish&id="+id+"&userid="+userid+"&sessionKey="+sessionKey);
+}
+
+function showCaption(id) {
+ document.getElementById('caption_'+id).toggleClassName('hidden');
+}
+
+function hidePreviewPublish(id) {
+ document.getElementById('prePub_'+id).toggleClassName('hidden');
+}
+
+function postPublish(id) {
+ lookupSession();
+ var ajax = new Ajax();
+ ajax.responseType = Ajax.FBML;
+ ajax.requireLogin = true;
+ ajax.ondone = function(transport) {
+ document.getElementById('prePub_'+id).setInnerFBML(transport);
+ document.getElementById('prePub_'+id).toggleClassName('hidden');
+ }
+ ajax.post(ajaxUrl+"?p=ajax&m=postPublish&id="+id+"&userid="+userid+"&sessionKey="+sessionKey);
+
+}
View
29 open-social-media-toolkit.tmproj
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>documents</key>
+ <array>
+ <dict>
+ <key>expanded</key>
+ <true/>
+ <key>name</key>
+ <string>open-social-media-toolkit</string>
+ <key>regexFolderFilter</key>
+ <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
+ <key>selected</key>
+ <true/>
+ <key>sourceDirectory</key>
+ <string></string>
+ </dict>
+ </array>
+ <key>fileHierarchyDrawerWidth</key>
+ <integer>200</integer>
+ <key>metaData</key>
+ <dict/>
+ <key>showFileHierarchyDrawer</key>
+ <true/>
+ <key>windowFrame</key>
+ <string>{{305, 0}, {1492, 1155}}</string>
+</dict>
+</plist>
View
96 php/console/controllers/admin_controller.php
@@ -0,0 +1,96 @@
+<?php
+
+Class AdminController extends AppController {
+ var $name = 'Admin';
+ public function cronjobs() {
+ $cronJobs = $this->db->load_all();
+ $this->set('cronJobs', $cronJobs);
+ $this->render();
+ }
+
+ public function run_cronjob() {
+ global $init;
+ require_once(PATH_CORE.'/classes/cron.class.php');
+ $cObj=new cron($init['apiKey']);
+ if (isset($_GET['task'])) {
+ $task = $_GET['task'];
+ $cObj->forceJob($task);
+ set_flash(array('notice' => "Cron job ($task) completed."));
+ redirect(url_for($this->name, 'cronjobs'));
+ } else {
+ set_flash(array('error' => "Invalid cron job -- aborted."));
+ redirect(url_for($this->name, 'cronjobs'));
+ }
+ }
+
+ public function initcronjobs() {
+ global $init;
+ require_once(PATH_CORE.'/classes/cron.class.php');
+ $cObj=new cron($init['apiKey']);
+ $cObj->initJobs();
+ set_flash(array('notice' => "Finished initializing cron jobs."));
+ redirect(url_for($this->name, 'cronjobs'));
+ }
+
+ public function cloud_properties() {
+ $this->render('not_implemented');
+ }
+
+ public function database() {
+ $this->render('not_implemented');
+ }
+
+ public function feed_list() {
+ $this->render('not_implemented');
+ }
+
+ public function index() {
+ $this->render();
+ }
+
+ public function flushfeeds() {
+ global $init;
+ require_once(PATH_CORE.'/classes/newswire.class.php');
+ $nwObj=new newswire();
+ $nwObj->cleanup(0);
+ set_flash(array('notice' => "Finished flushing feeds."));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function sitestatus() {
+ global $init;
+ require_once(PATH_CORE.'/classes/systemStatus.class.php');
+ $ssObj=new systemStatus();
+ $siteStatus=$ssObj->getState('siteStatus');
+ if ($siteStatus=='offline')
+ $siteStatus='online';
+ else
+ $siteStatus='offline';
+ $ssObj->setState('siteStatus',$siteStatus);
+ $q=$ssObj->db->query("select email from User where isAdmin=1;");
+ while ($data=$ssObj->db->readQ($q)) {
+ // Notify the admins
+ mail($data->email, SITE_TITLE.' Site Status: '.$siteStatus, 'Someone just toggled '.SITE_TITLE.' site status. The site is now '.$siteStatus, 'From: support@newscloud.com'."\r\n");
+ }
+ set_flash(array('notice' => "Site Status Toggled! New site status is $siteStatus"));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function insert_survey_monkey_data() {
+ require_once(PATH_CORE.'/classes/researchSurveyMonkey.class.php');
+ $surveyMonkeyTable = new SurveyMonkeyTable();
+
+ $result = $surveyMonkeyTable->loadCSV();
+
+ if (substr($result, 0, 5) == 'ERROR') {
+ set_flash(array('error' => $result));
+ } else {
+ set_flash(array('notice' => $result));
+ }
+
+ redirect(url_for($this->name, 'index'));
+ }
+
+}
+
+?>
View
75 php/console/controllers/app_controller.php
@@ -0,0 +1,75 @@
+<?php
+
+class AppController {
+ var $name;
+ var $params;
+ var $filters = false;
+ var $db;
+ var $render_vars;
+ var $helpers = array('application');
+ var $skip_render = false;
+
+ function __construct() {
+ global $params;
+ global $db;
+ global $controller_name;
+ global $action_name;
+ $this->params = $params;
+ $this->action = $params['action'];
+ $this->db = $db;
+ $controller_name = strtolower($this->name);
+ $action_name = $this->action;
+ $this->render_vars = array();
+
+ // Run before_filter
+ $this->before_filter();
+ }
+
+ function render($view = false) {
+ if (!$view)
+ $view = $this->action;
+
+
+ if (!$this->skip_render) {
+ // Set some local view variables
+ $this->set_class_vars();
+ // Load helper files
+ foreach ($this->helpers as $helper) {
+ $file = PATH_CONSOLE.'/helpers/'.$helper.'_helper.php';
+ require_once($file);
+ }
+
+ if (file_exists(PATH_CONSOLE.'/views/'.strtolower($this->name).'/'.$view.'.php')) {
+ foreach ($this->render_vars as $name => $value)
+ $$name = $value;
+ disp_header();
+ require(PATH_CONSOLE.'/views/'.strtolower($this->name).'/'.$view.'.php');
+ disp_footer();
+ } else {
+ set_flash(array('error' => 'Action does not exist.'));
+ redirect(url_for($this->name));
+ }
+ }
+
+ // Run after filter
+ $this->after_filter();
+ }
+
+ protected function set($name, &$value) {
+ $this->render_vars[$name] = $value;
+ }
+
+ private function set_class_vars() {
+ $this->set('controller_name', strtolower($this->name));
+ $this->set('action_name', $this->action);
+ }
+
+ protected function before_filter() {
+ }
+
+ protected function after_filter() {
+ }
+
+}
+
+?>
View
90 php/console/controllers/dashpods_controller.php
@@ -0,0 +1,90 @@
+<?php
+
+Class DashpodsController extends AppController {
+ var $name = 'Dashpods';
+ public function index() {
+ $this->render();
+ }
+
+ public function main() {
+ $pod_list = array('ActionStats', 'SessionLength', 'UserReport', 'MemberStats', 'MostReadStories');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function stats() {
+ $pod_list = array('MemberStats', 'ActionStats', 'SessionStatistics', 'SessionLength');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function stories() {
+ $pod_list = array('TopRatedStories', 'MostReadStories', 'MostDiscussedStories', 'MostShared', 'StoryReport');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function geo() {
+ $pod_list = array('CityDistribution', 'CountryDistribution', 'StateDistribution');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function members() {
+ $pod_list = array('ActionStats', 'MemberStats', 'AgeDistribution', 'GenderDistribution', 'EmailDistribution', 'InterestDistribution', 'UserReport', 'TotalMembers');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function challenges() {
+ $pod_list = array('ChallengeReport', 'ChallengeChart');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ public function misc() {
+ $pod_list = array('ActionStats');
+
+ echo $this->build_pods_json($pod_list);
+ }
+
+ private function build_pods_json($pod_list = false) {
+ if (!$pod_list || !is_array($pod_list)) return false;
+
+
+ global $poddb;
+ $jsonData = array();
+ $pods = $poddb->get_pods();
+ foreach ($pods as $podname => $pod) {
+ if (in_array($podname, $pod_list)) {
+ $podh = load_pod($pod);
+ $jsonData[] = $podh->gen_pod();
+ } else {
+ continue;
+ }
+ }
+ if (count($jsonData)) {
+ if (isset($new_js)) {
+ $fullData = array('Pods' => $jsonData);
+ $fullData['filters'] = $filters;
+ $fullData['groups'] = $groups;
+ return json_encode($fullData);
+ } else {
+ return json_encode($jsonData);
+ }
+ }
+ }
+
+ protected function before_filter() {
+ if (!isset($this->params['load']))
+ $this->base_page();
+ }
+
+ protected function base_page() {
+ $this->render('base_page');
+ exit;
+ }
+
+}
+
+?>
View
75 php/console/controllers/facebook_controller.php
@@ -0,0 +1,75 @@
+<?php
+
+Class FacebookController extends AppController {
+ var $name = 'Facebook';
+ public function registerfeedtemplates() {
+ global $init;
+ include_once PATH_FACEBOOK.'/lib/facebook.php';
+ $facebook = new Facebook($init['fbAPIKey'], $init['fbSecretKey']);
+ require_once (PATH_FACEBOOK.'/classes/profileBoxes.class.php');
+ $proObj=new profileBoxes($this->db);
+ $proObj->loadFacebook($facebook);
+ $proObj->registerFeedTemplates();
+ set_flash(array('notice' => "Path templates (".PATH_TEMPLATES."). Finished registering feed templates."));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function deletefeedtemplates() {
+ global $init;
+ include_once PATH_FACEBOOK.'/lib/facebook.php';
+ $facebook = new Facebook($init['fbAPIKey'], $init['fbSecretKey']);
+ require_once (PATH_FACEBOOK.'/classes/profileBoxes.class.php');
+ $proObj=new profileBoxes($this->db);
+ $proObj->loadFacebook($facebook);
+ $proObj->deleteFeedTemplates();
+ set_flash(array('notice' => "Path templates (".PATH_TEMPLATES."). Finished deleting feed templates."));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function initprofilebox() {
+ global $init;
+ include_once PATH_FACEBOOK.'/lib/facebook.php';
+ $facebook = new Facebook($init['fbAPIKey'], $init['fbSecretKey']);
+ require_once (PATH_FACEBOOK.'/classes/profileBoxes.class.php');
+ $proObj=new profileBoxes($this->db);
+ $proObj->loadFacebook($facebook);
+ $proObj->initRefHandle();
+ set_flash(array('notice' => "Finished initializing profile box."));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function downloadsettings() {
+ global $init;
+
+ /* initialize the SMT Facebook appliation class, NO Facebook library */
+ require_once (PATH_CORE.'/classes/systemStatus.class.php');
+ $ssObj=new systemStatus();
+ require_once PATH_FACEBOOK."/classes/app.class.php";
+ $app=new app(NULL,true);
+ $facebook=&$app->loadFacebookLibrary();
+// 'default_action_fbml','default_fbml','post_install_url',
+ $propList=array('application_name','authorize_url','base_domain','callback_url','dashboard_url','default_column','description','desktop','dev_mode','edit_url','email','help_url','info_changed_url','installable','ip_list','is_mobile','message_action','message_url','post_authorize_redirect_url','privacy_url','private_install','profile_tab_url','publish_action','publish_self_action','publish_self_url','publish_url','see_all_url','tab_default_name','uninstall_url','use_iframe','wide_mode');
+ $props=$facebook->api_client->admin_getAppProperties($propList);
+ $this->set('props', $props);
+ $this->set('ssObj', $ssObj);
+
+ $this->render();
+ }
+
+ public function syncallocations() {
+ global $init;
+ require_once(PATH_CORE.'/classes/cron.class.php');
+ $cObj=new cron($init['apiKey']);
+ $cObj->forceJob('facebookAllocations');
+ echo 'Completed';
+ set_flash(array('notice' => "Finished synching allocations"));
+ redirect(url_for($this->name, 'index'));
+ }
+
+ public function index() {
+ $this->render();
+ }
+
+}
+
+?>
View
48 php/console/controllers/main_controller.php
@@ -0,0 +1,48 @@
+<?php
+
+class MainController extends AppController {
+ var $name = 'Main';
+ public function editorial() {
+ $this->render('not_implemented');
+ }
+
+ public function membership() {
+ $this->render('not_implemented');
+ }
+
+ public function site() {
+ $this->render('not_implemented');
+ }
+
+ public function index() {
+ //$this->render('not_implemented');
+ $this->render('dashboard');
+ }
+
+ public function load() {
+ global $filters;
+ global $groups;
+
+ $jsonData = array();
+ $pods = $this->db->get_pods();
+ foreach ($pods as $podname => $pod) {
+ $podh = load_pod($pod);
+ $jsonData[] = $podh->gen_pod();
+ }
+ if (count($jsonData)) {
+ if ($new_js) {
+ $fullData = array('Pods' => $jsonData);
+ $fullData['filters'] = $filters;
+ $fullData['groups'] = $groups;
+ echo json_encode($fullData);
+ } else {
+ echo json_encode($jsonData);
+ }
+ } else {
+ }
+ $this->skip_render = true;
+ }
+
+}
+
+?>
View
657 php/console/controllers/members_controller.php
@@ -0,0 +1,657 @@
+<?php
+
+Class MembersController extends AppController {
+ var $name = 'Members';
+ /****************************************************************
+ * Manage Members section
+ ***************************************************************/
+ public function members() {
+ $members = $this->db->load_all();
+ $this->set('members', $members);
+ $this->render();
+ }
+
+ public function view_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ $sql = "SELECT User.*, UserInfo.* FROM User, UserInfo WHERE User.userid = $id AND User.userid = UserInfo.userid";
+ if (($member_res = $this->db->query($sql))) {
+ $member = mysql_fetch_assoc($member_res);
+ $this->set('member', $member);
+
+ $comment_sql = "select title,Content.siteContentId,concat(comments) as comments,Comments.date FROM Comments LEFT JOIN Content ON Content.siteContentId=Comments.SiteContentId WHERE Comments.userid={$member['userid']}";
+ $comments_res = $this->db->query($comment_sql);
+ $comments = array();
+ while (($comment = mysql_fetch_assoc($comments_res)) !== false)
+ $comments[] = $comment;
+ $this->set('comments', $comments);
+
+ $challenges_sql = "select challengeid,title,concat(evidence) as evidence,ChallengesCompleted.status,dateSubmitted,pointsAwarded,concat(comments) as comments from ChallengesCompleted LEFT JOIN Challenges ON Challenges.id=ChallengesCompleted.challengeid WHERE userid = {$member['userid']} ORDER BY dateSubmitted";
+ $challenges_res = $this->db->query($challenges_sql);
+ $challenges = array();
+ while (($challenge = mysql_fetch_assoc($challenges_res)) !== false)
+ $challenges[] = $challenge;
+ $this->set('challenges', $challenges);
+
+ $blogs_sql = "select * from Content where isBlogEntry=1 and userid = {$member['userid']}";
+ $blogs_res = $this->db->query($blogs_sql);
+ $blogs = array();
+ while (($blog = mysql_fetch_assoc($blogs_res)) !== false)
+ $blogs[] = $blog;
+ $this->set('blogs', $blogs);
+
+ $stories_sql = "select * from Content where isBlogEntry=0 and userid = {$member['userid']}";
+ $stories_res = $this->db->query($stories_sql);
+ $stories = array();
+ while (($story = mysql_fetch_assoc($stories_res)) !== false)
+ $stories[] = $story;
+ $this->set('stories', $stories);
+
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function new_member() {
+ $this->render();
+ }
+
+ public function create_member() {
+ if (isset($_POST['member']['name'])) {
+ if ($_POST['member']['dateRegistered'] == '')
+ $_POST['member']['dateRegistered'] = date("Y-m-d H:i:s", time());
+ //$id = $this->db->insert($_POST['member']);
+ if (($id = $this->db->insert($_POST['member'])) > 0) {
+ //if (preg_match('/^[0-9]+$/', $id)) {
+ set_flash(array('notice' => 'Successfully created member!'));
+ redirect(url_for('members', 'view_member', $id));
+ } else {
+ set_flash(array('error' => 'Could not create your member! Please try again. '.$id));
+ redirect(url_for('members', 'new_member'));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'new_member'));
+ }
+ }
+
+
+
+ public function modify_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ if (($member = $this->db->load($id))) {
+ $this->set('member', $member);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function update_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ if (isset($_POST['member']['name'])) {
+ if (($result = $this->db->update($_POST['member'])) == 1) {
+ set_flash(array('notice' => 'Successfully updated member.'));
+ redirect(url_for('members', 'view_member', $id));
+ } else {
+ set_flash(array('error' => 'Could not update your member! Please try again. '.$result));
+ redirect(url_for('members', 'modify_member', $id));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'modify_member', $id));
+ }
+ }
+
+ public function block_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ if (($result = $this->db->block($id, 1)) == 1) {
+ set_flash(array('notice' => 'Successfully blocked member.'));
+ redirect(url_for('members', 'members'));
+ } else {
+ set_flash(array('error' => 'Could not block member. Please try again. '.$result));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function unblock_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ if (($result = $this->db->block($id, 0)) == 1) {
+ set_flash(array('notice' => 'Successfully unblocked member.'));
+ redirect(url_for('members', 'members'));
+ } else {
+ set_flash(array('error' => 'Could not unblock member. Please try again. '.$result));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function destroy_member() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ if (($result = $this->db->delete($id)) == 1) {
+ set_flash(array('notice' => 'Successfully deleted member.'));
+ redirect(url_for('members', 'members'));
+ } else {
+ set_flash(array('error' => 'Could not delete member. Please try again. '.$result));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function authorize_editing() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+ $sql = "SELECT User.*, UserInfo.* FROM User, UserInfo WHERE User.userid = $id AND User.userid = UserInfo.userid";
+ if (($member_res = $this->db->query($sql))) {
+ $member = mysql_fetch_assoc($member_res);
+ //if (($member = $this->db->load($id))) {
+ //require('views/modify_member.php');
+ require_once(PATH_CORE . '/classes/dynamicTemplate.class.php');
+ require_once(PATH_CORE .'/classes/dynamicTemplate.class.php');
+ $dynTemp = dynamicTemplate::getInstance();
+ $authorized = $dynTemp->authorizeFbIdForEditing($member['fbId']);
+ set_flash(array('notice' => "Authorizing $fbId...authorized fbIds now $authorized"));
+ redirect(url_for('members', 'members'));
+ } else {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for('members', 'members'));
+ }
+ }
+
+ public function show_friend_invite_credits() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member for id: $id"));
+ redirect(url_for($this->name, 'members'));
+ }
+
+ $query =
+ "SELECT name, User.userid, dateRegistered, WEEK(dateRegistered,1) AS week, email, fbId
+ FROM User,UserInfo,Log
+ WHERE User.userid=UserInfo.userid
+ AND Log.userid1=$id
+ AND Log.action='friendSignup'
+ AND User.userid=Log.userid2
+ ORDER BY dateRegistered DESC;";
+
+ $res = $this->db->query($query);
+ while ($row=mysql_fetch_assoc($res))
+ {
+ $friends []= $row;
+ }
+
+ $this->set('friends', $friends);
+
+ $this->render();
+
+
+ }
+
+
+ /****************************************************************
+ * Manage Outbound Messages section
+ ***************************************************************/
+ public function outboundmessages() {
+ $outboundmessages = $this->db->load_all();
+ $this->set('outboundmessages', $outboundmessages);
+ $this->render();
+ }
+
+ public function view_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (($outboundmessage = $this->db->load($id))) {
+ $this->set('outboundmessage', $outboundmessage);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current outboundmessage for id: $id"));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ public function new_outboundmessage() {
+ $this->render();
+ }
+
+ public function create_outboundmessage() {
+ if (isset($_POST['outboundmessage']['msgBody'])) {
+ if ($_POST['outboundmessage']['t'] == '')
+ $_POST['outboundmessage']['t'] = date("Y-m-d H:i:s", time());
+ $userGroup = '';
+ switch($_POST['outboundmessage']['userGroup']) {
+ case 'all':
+ $userGroup = '';
+ break;
+ case 'members':
+ $userGroup = 'User.isMember = 1';
+ break;
+ case 'nonmembers':
+ $userGroup = 'User.isMember = 0';
+ break;
+ case 'teampotential':
+ $userGroup = "User.isMember = 0 AND UserInfo.age<=25 AND UserInfo.age>=16 AND User.eligibility<>'ineligible'";
+ break;
+ case 'team':
+ $userGroup = "User.eligibility='team'";
+ break;
+ case 'general':
+ $userGroup = "User.eligibility='general'";
+ break;
+ case 'admin':
+ $userGroup = 'User.isAdmin = 1';
+ break;
+ default:
+ $userGroup = '';
+ break;
+ }
+ $_POST['outboundmessage']['userGroup'] = $userGroup;
+ //$id = $this->db->insert($_POST['outboundmessage']);
+ if (($id = $this->db->insert($_POST['outboundmessage'])) > 0) {
+ //if (preg_match('/^[0-9]+$/', $id)) {
+ set_flash(array('notice' => 'Successfully created outboundmessage!'));
+ redirect(url_for('members', 'view_outboundmessage', $id));
+ } else {
+ set_flash(array('error' => 'Could not create your outboundmessage! Please try again. '.$id));
+ redirect(url_for('members', 'new_outboundmessage'));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'new_outboundmessage'));
+ }
+ }
+
+ public function modify_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (($outboundmessage = $this->db->load($id))) {
+ $this->set('outboundmessage', $outboundmessage);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current outboundmessage for id: $id"));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ public function update_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (isset($_POST['outboundmessage']['msgBody'])) {
+ $userGroup = '';
+ switch($_POST['outboundmessage']['userGroup']) {
+ case 'all':
+ $userGroup = '';
+ break;
+ case 'members':
+ $userGroup = 'User.isMember = 1';
+ break;
+ case 'nonmembers':
+ $userGroup = 'User.isMember = 0';
+ break;
+ case 'teampotential':
+ $userGroup = "User.isMember = 0 AND UserInfo.age<=25 AND UserInfo.age>=16 AND User.eligibility<>'ineligible'";
+ break;
+ case 'team':
+ $userGroup = "User.eligibility='team'";
+ break;
+ case 'general':
+ $userGroup = "User.eligibility='general'";
+ break;
+ case 'admin':
+ $userGroup = 'User.isAdmin = 1';
+ break;
+ default:
+ $userGroup = '';
+ break;
+ }
+ $_POST['outboundmessage']['userGroup'] = $userGroup;
+ if (($result = $this->db->update($_POST['outboundmessage'])) == 1) {
+ set_flash(array('notice' => 'Successfully updated outboundmessage.'));
+ redirect(url_for('members', 'view_outboundmessage', $id));
+ } else {
+ set_flash(array('error' => 'Could not update your outboundmessage! Please try again. '.$result));
+ redirect(url_for('members', 'modify_outboundmessage', $id));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'modify_outboundmessage', $id));
+ }
+ }
+
+ public function send_outboundmessage() {
+ global $init;
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (isset($_GET['preview']) && $_GET['preview'] == 'true') {
+ $preview = true;
+ } else {
+ $preview = false;
+ }
+ if (($outboundmessage = $this->db->load($id))) {
+ $extraWhere = '';
+ $optInWhere = '';
+ $userGroupWhere = '';
+ if ($outboundmessage['msgType'] == 'announce') {
+ $optInWhere = ' User.optInEmail = 1 AND ';
+ }
+
+ if ($outboundmessage['userGroup'] != '' || $preview) {
+ if (!$preview) {
+ $userGroupWhere = ' '.$outboundmessage['userGroup'].' AND ';
+ } else {
+ $userGroupWhere = ' User.isAdmin = 1 AND ';
+ }
+ }
+
+ if ($outboundmessage['status'] == 'hold') {
+ set_flash(array('error' => "This message is marked as 'hold' and cannot be sent. Change the status of this message and try again."));
+ redirect(url_for('members', 'outboundmessages'));
+ exit;
+ } else if ($outboundmessage['status'] == 'sent') {
+ set_flash(array('error' => "This message has already been sent and cannot be resent."));
+ redirect(url_for('members', 'outboundmessages'));
+ exit;
+ } else if ($outboundmessage['status'] == 'incomplete') {
+ $received = $outboundmessage['usersReceived'];
+ if ($received != '')
+ $extraWhere = " AND UserInfo.fbId NOT IN ($received)";
+ } else {
+ }
+ include_once PATH_FACEBOOK.'/lib/facebook.php';
+ $facebook = new Facebook($init['fbAPIKey'], $init['fbSecretKey']);
+ //$usersResult = $this->db->query("SELECT User.userid, fbId FROM User LEFT JOIN UserInfo ON User.userid = UserInfo.userid WHERE optInEmail = 1 $extraWhere");
+ $usersResult = $this->db->query("SELECT User.userid, UserInfo.fbId FROM User, UserInfo WHERE $optInWhere $userGroupWhere User.userid = UserInfo.userid $extraWhere");
+ $users = '';
+ while (($row = mysql_fetch_row($usersResult)) !== false)
+ $users .= "{$row[1]},";
+ $users = substr($users, 0, -1);
+ $usersArr = array();
+ $totalUsers = 0;
+ if (preg_match('/^[0-9]+/', $users)) {
+ //$totalUsers = substr_count($users, ',') + 1;
+ $users = preg_replace('/,{2,}/', ',', $users);
+ $usersArr = split(',', $users);
+ $totalUsers = count($usersArr);
+ } else {
+ set_flash(array('error' => "No current opted in users to send emails to."));
+ redirect(url_for('members', 'outboundmessages'));
+ exit;
+ }
+ $userCount = 0;
+ $totalSent = 0;
+ $usersReceived = '';
+ while ($userCount < $totalUsers) {
+ $sendCount = 0;
+ $currEmailUsers = '';
+ $emailsLeft = min(99, $totalUsers - $totalSent);
+ while ($sendCount++ < $emailsLeft)
+ if (isset($usersArr[$userCount]) && $usersArr[$userCount] != '')
+ $currEmailUsers .= $usersArr[$userCount++].',';
+ $currEmailUsers = substr($currEmailUsers, 0, -1);
+ $msg = '';
+ ob_start();
+ require(PATH_CONSOLE.'/views/members/send_outboundmessage.php');
+ $msg = ob_get_contents();
+ ob_end_clean();
+ if ($outboundmessage['msgType'] == 'announce') {
+ $result = $facebook->api_client->notifications_sendEmail($currEmailUsers, $outboundmessage['subject'], '', $msg);
+ } else if ($outboundmessage['msgType'] == 'notification') {
+ $result = $facebook->api_client->notifications_send($currEmailUsers, $msg, 'app_to_user');
+ } else {
+ set_flash(array('error' => 'Invalid message type!'));
+ redirect(url_for('members', 'outboundmessages'));
+ exit;
+ }
+ if (preg_match('/^[0-9]+/', $result)) {
+ $usersReceived .= $result.',';
+ $totalSent += substr_count($result, ',') + 1;
+ set_flash(array('notice' => "Successfully sent your outbound message to $totalSent users out of $totalUsers total."));
+ } else {
+ set_flash(array('error' => "Failed to send your outbound message: $result"));
+ break;
+ }
+ }
+ $usersReceived = substr($usersReceived, 0, -1);
+ // Update stats
+ if ($totalSent == $totalUsers) {
+ if (!$preview)
+ $status = 'sent';
+ else
+ $status = 'pending';
+ } else {
+ set_flash(array('error' => "Incomplete notifications, only $totalSent out of $totalUsers messages were sent!"));
+ if (!$preview)
+ $status = 'incomplete';
+ else
+ $status = 'pending';
+ }
+ $this->db->query("UPDATE OutboundMessages set usersReceived = '$usersReceived', numUsersReceived = '$totalSent', numUsersExpected = '$totalUsers', status = '$status' WHERE id = '{$outboundmessage['id']}'");
+ redirect(url_for('members', 'outboundmessages'));
+ } else {
+ set_flash(array('error' => "Sorry no current outboundmessage for id: $id"));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ public function block_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (($result = $this->db->block($id, 1)) == 1) {
+ set_flash(array('notice' => 'Successfully blocked outboundmessage.'));
+ redirect(url_for('members', 'outboundmessages'));
+ } else {
+ set_flash(array('error' => 'Could not block outboundmessage. Please try again. '.$result));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ public function unblock_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (($result = $this->db->block($id, 0)) == 1) {
+ set_flash(array('notice' => 'Successfully unblocked outboundmessage.'));
+ redirect(url_for('members', 'outboundmessages'));
+ } else {
+ set_flash(array('error' => 'Could not unblock outboundmessage. Please try again. '.$result));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ public function destroy_outboundmessage() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current outbound message for id: $id"));
+ redirect(url_for($this->name, 'outboundmesages'));
+ }
+ if (($result = $this->db->delete($id)) == 1) {
+ set_flash(array('notice' => 'Successfully deleted outboundmessage.'));
+ redirect(url_for('members', 'outboundmessages'));
+ } else {
+ set_flash(array('error' => 'Could not delete outboundmessage. Please try again. '.$result));
+ redirect(url_for('members', 'outboundmessages'));
+ }
+ }
+
+ /****************************************************************
+ * Manage Member Emails section
+ ***************************************************************/
+ public function member_emails() {
+ $new_contact_emails = $this->db->load_all();
+ $this->set('new_contact_emails', $new_contact_emails);
+ $this->render();
+ }
+
+ public function clean_up_member_emails() {
+ $result = $this->db->query("TRUNCATE ContactEmails");
+ if (preg_match('/query/i', $result))
+ set_flash(array('error' => $result));
+ else if (preg_match('/^[0-9]+$/', $result))
+ set_flash(array('notice' => 'Successfully deleted all member contact emails.'));
+ else
+ set_flash(array('notice' => $result));
+ redirect(url_for('members', 'member_emails'));
+ }
+
+ public function view_member_email() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current member email for id: $id"));
+ redirect(url_for($this->name, 'member_emails'));
+ }
+ if (($member_email = $this->db->load($id))) {
+ $this->set('member_email', $member_email);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current member_email for id: $id"));
+ redirect(url_for('members', 'member_emails'));
+ }
+ }
+
+ /****************************************************************
+ * Manage Forum Topics section
+ ***************************************************************/
+ public function forumtopics() {
+ $forumtopics = $this->db->load_all();
+ $this->set('forumtopics', $forumtopics);
+ $this->render();
+ }
+
+ public function view_forumtopics() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for($this->name, 'forumtopics'));
+ }
+ if (($forumtopic = $this->db->load($id))) {
+ $this->set('forumtopic', $forumtopic);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for('members', 'forumtopics'));
+ }
+ }
+
+ public function new_forumtopic() {
+ $this->render();
+ }
+
+ public function create_forumtopic() {
+ if (isset($_POST['forumtopic']['title'])) {
+ if ($_POST['forumtopic']['lastChanged'] == '')
+ $_POST['forumtopic']['lastChanged'] = date("Y-m-d H:i:s", time());
+ if (($id = $this->db->insert($_POST['forumtopic'])) > 0) {
+ set_flash(array('notice' => 'Successfully created forumtopic!'));
+ redirect(url_for('members', 'forumtopics', $id));
+ } else {
+ set_flash(array('error' => 'Could not create your forumtopic! Please try again. '.$id));
+ redirect(url_for('members', 'new_forumtopic'));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'new_forumtopic'));
+ }
+ }
+
+ public function modify_forumtopic() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for($this->name, 'forumtopics'));
+ }
+ if (($forumtopic = $this->db->load($id))) {
+ $this->set('forumtopic', $forumtopic);
+ $this->render();
+ } else {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for('members', 'forumtopics'));
+ }
+ }
+
+ public function update_forumtopic() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for($this->name, 'forumtopics'));
+ }
+ if (isset($_POST['forumtopic']['title'])) {
+ if (($result = $this->db->update($_POST['forumtopic'])) == 1) {
+ set_flash(array('notice' => 'Successfully updated forumtopic.'));
+ redirect(url_for('members', 'forumtopics', $id));
+ } else {
+ set_flash(array('error' => 'Could not update your forumtopic! Please try again. '.$result));
+ redirect(url_for('members', 'modify_forumtopic', $id));
+ }
+ } else {
+ set_flash(array('error' => 'Form data not submitted properly, please try again.'));
+ redirect(url_for('members', 'modify_forumtopic', $id));
+ }
+ }
+
+ public function destroy_forumtopic() {
+ $id = $this->params['id'];
+ if ($id === 0) {
+ set_flash(array('error' => "Sorry no current forumtopic for id: $id"));
+ redirect(url_for($this->name, 'forumtopics'));
+ }
+ if (($result = $this->db->delete($id)) == 1) {
+ set_flash(array('notice' => 'Successfully deleted forumtopic.'));
+ redirect(url_for('members', 'forumtopics'));
+ } else {
+ set_flash(array('error' => 'Could not delete forumtopic. Please try again. '.$result));
+ redirect(url_for('members', 'forumtopics'));
+ }
+ }
+
+
+ public function index() {
+ $this->render();
+ }
+
+}
+
+
+?>
View
127 php/console/controllers/settings_controller.php
@@ -0,0 +1,127 @@
+<?php
+
+Class SettingsController extends AppController {
+ var $name = 'Settings';
+ public function index() {
+ $this->render();
+ }
+ public function initialize_tables() {
+ $tables = array();
+ $sql = "SHOW TABLES";
+ //if ($this->dbname)
+ if (isset($_REQUEST['dbname']) && $_REQUEST['dbname'])
+ $this->db->selectdb($_REQUEST['dbname']);
+ $tableresults = $this->db->query($sql);
+
+ while (($row = mysql_fetch_assoc($tableresults)) !== false) {
+ $tablename = array_shift($row);
+ if (preg_match('/^Admin/', $tablename))
+ continue;
+ $tables[$tablename] = array();
+ $tables[$tablename]['name'] = $tablename;
+ $tables[$tablename]['fields'] = array();
+ $tsql = "DESCRIBE $tablename";
+ $fieldresults = mysql_query($tsql);
+
+ while (($trow = mysql_fetch_assoc($fieldresults)) !== false) {
+ $type = 'string';
+ switch ($trow['Type']) {
+ case (preg_match('/^varchar/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'string';
+ break;
+ case (preg_match('/^int/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'number';
+ break;
+ case (preg_match('/^tinyint/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'boolean';
+ break;
+ case (preg_match('/^enum/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'enum';
+ break;
+ case (preg_match('/^(datetime|timestamp)/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'date';
+ break;
+ case (preg_match('/^text/i', $trow['Type']) ? $trow['Type'] : !$trow['Type']):
+ $type = 'text';
+ break;
+ default:
+ $type = 'string';
+ break;
+ }
+ $tables[$tablename]['fields'][$trow['Field']] = array(
+ 'fieldtype' => $trow['Type'],
+ 'type' => $type,
+ 'null' => $trow['Null'],
+ 'key' => $trow['Key'],
+ 'default' => $trow['Default'],
+ 'extra' => $trow['Extra']
+ );
+