Source for file edit_offering_details.act.php

Documentation is available at edit_offering_details.act.php

  1. <?php
  2.  
  3. /**
  4. * This action is the central page for viewing and modifying course offering information.
  5. *
  6. * @package polyphony.coursemanagement
  7. *
  8. *
  9. * @since 7/28/06
  10. *
  11. * @copyright Copyright &copy; 2006, Middlebury College
  12. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  13. *
  14. * @version $Id: edit_offering_details.act.php,v 1.11 2007/09/19 14:04:54 adamfranco Exp $
  15. */
  16.  
  17. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  18. require_once(HARMONI."GUIManager/Components/Blank.class.php");
  19. require_once(POLYPHONY."/main/modules/coursemanagement/edit_section_details.act.php");
  20.  
  21. class edit_offering_detailsAction
  22. extends MainWindowAction
  23. {
  24. /**
  25. * Check Authorizations
  26. *
  27. * @return boolean
  28. * @access public
  29. * @since 4/26/05
  30. */
  31. function isAuthorizedToExecute () {
  32. // Check for authorization
  33. $authZManager = Services::getService("AuthZ");
  34. $idManager = Services::getService("IdManager");
  35. $harmoni = Harmoni::instance();
  36. $harmoni->request->startNamespace("polyphony-agents");
  37. $offeringIdString = $harmoni->request->get("courseId");
  38.  
  39. $harmoni->request->endNamespace();
  40. if ($authZManager->isUserAuthorized(
  41. $idManager->getId("edu.middlebury.authorization.modify"),
  42. $idManager->getId($offeringIdString)))
  43. {
  44. return TRUE;
  45. } else
  46. return FALSE;
  47. }
  48. /**
  49. * Return the heading text for this action, or an empty string.
  50. *
  51. * @return string
  52. * @access public
  53. * @since 4/26/05
  54. */
  55. function getHeadingText () {
  56. $harmoni = Harmoni::instance();
  57. $harmoni->request->startNamespace("polyphony-agents");
  58. $harmoni->request->passthrough("courseId");
  59. $offeringIdString = $harmoni->request->get("courseId");
  60. $idManager = Services::getService("Id");
  61. $offeringId =$idManager->getId($offeringIdString);
  62. $cm = Services::getService("CourseManagement");
  63. $offering =$cm->getCourseOffering($offeringId);
  64. return dgettext("polyphony", $offering->getDisplayName());
  65. }
  66. /**
  67. * Build the content for this action
  68. *
  69. * @return void
  70. * @access public
  71. * @since 4/26/05
  72. */
  73. function buildContent () {
  74. $defaultTextDomain = textdomain("polyphony");
  75. $actionRows =$this->getActionRows();
  76. //$pageRows = new Container(new YLayout(), OTHER, 1);
  77. $harmoni = Harmoni::instance();
  78. $harmoni->request->startNamespace("polyphony-agents");
  79. $harmoni->request->passthrough("courseId");
  80. $offeringIdString = $harmoni->request->get("courseId");
  81. $furtherAction = $harmoni->request->get("furtherAction");
  82.  
  83. $idManager = Services::getService("Id");
  84. $offeringId =$idManager->getId($offeringIdString);
  85. $cm = Services::getService("CourseManagement");
  86. $offering =$cm->getCourseOffering($offeringId);
  87.  
  88. ob_start();
  89. if (!$furtherAction) $furtherAction = "edit_offering_detailsAction::viewOfferingDetails";
  90. $actionFunctions = array(
  91. "edit_offering_detailsAction::viewOfferingDetails",
  92. "edit_offering_detailsAction::confirmDeleteOffering",
  93. "edit_offering_detailsAction::deleteOffering",
  94. );
  95. if($furtherAction && in_array($furtherAction, $actionFunctions)){
  96. eval($furtherAction.'($offering);');
  97. }
  98. // Layout
  99. $actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  100. ob_end_clean();
  101. $harmoni->request->forget("courseId");
  102. $harmoni->request->endNamespace();
  103. textdomain($defaultTextDomain);
  104. }
  105.  
  106. /***************************FUNCTIONS***************************************/
  107.  
  108.  
  109. /**
  110. * shows the details of the offering's properties and gives menu of actions
  111. *
  112. * @param object Agent $agent
  113. * @return void
  114. * @access public
  115. * @since 7/19/05
  116. */
  117. function viewOfferingDetails($offering){
  118. edit_offering_detailsAction::refreshOfferingDetails($offering);
  119.  
  120. $offeringId =$offering->getId();
  121. $offeringIdString = $offeringId->getIdString();
  122. //display offering info
  123. //print "\n<h3>".$offering->getDisplayName()."</h3>";
  124. print "<div style='margin-left: 15px'>";
  125. print "\n<table><tr><td>";
  126. //print "\n<table bgcolor='#AAAAAA' cellspacing='1' cellpadding='3'>";
  127.  
  128. //print "\n\t<tr><td>";
  129. $term =$offering->getTerm();
  130. print "\n<h1>".$offering->getDisplayName()." - ".$term->getDisplayName()."</h1>";
  131.  
  132. /*
  133. print "\n\t\t<td>Display Name</td>";
  134. print "\n\t\t<td>";
  135. print $offering->getDisplayName();
  136. print "</td>";
  137. print "\n\t</tr>";
  138. print "\n\t<tr>";
  139. print "\n\t\t<td>Number</td>";
  140. print "\n\t\t<td>";
  141. print $offering->getNumber();
  142. print "</td>";
  143. print "\n\t</tr>";
  144. print "\n\t<tr>";
  145. print "\n\t\t<td>Term</td>";
  146. print "\n\t\t<td>";
  147. $term =$offering->getTerm();
  148. print $term->getDisplayName();
  149. */
  150. //print "</td>";
  151. //print "\n\t</tr>";
  152. //print "\n</table>";
  153. print "\n</td><td>";
  154.  
  155. //actions menu
  156. $harmoni = Harmoni::instance();
  157. $url =$harmoni->request->mkURL();
  158. $link1 = $harmoni->request->quickURL("coursemanagement", "createcoursesection",
  159. array("offeringId=>$offeringIdString"));
  160. $link2 = $harmoni->request->quickURL("coursemanagement", "createcourse");
  161. print "<ul>
  162. <li><a href='".$url->write("furtherAction","edit_offering_detailsAction::editOffering")."'>Edit Offering</a></li>
  163. <li><a href='".$url->write("furtherAction","edit_offering_detailsAction::deleteOffering")."'>Delete Offering</a></li>
  164. <li><a href='".$link1."'>Add a course section</a></li>
  165. <li><a href='".$link2."'>Add a new course offering</a></li>
  166. </ul>";
  167. print "\n</td></tr></table>";
  168. print "</div>";
  169. $actionRows =$this->getActionRows();
  170. //$actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  171. //ob_end_clean();
  172.  
  173. //ob_start();
  174. //$actionRows =$this->getActionRows();
  175. //$pageRows = new Container(new YLayout(), OTHER, 1);
  176. $sections =$offering->getCourseSections();
  177. //print "<h2>Sections:</h2>";
  178. while($sections->hasNextCourseSection()){
  179. $actionRows->add(new Block(ob_get_contents(),2),"100%", null, CENTER, TOP);
  180. ob_end_clean();
  181.  
  182. ob_start();
  183. $actionRows =$this->getActionRows();
  184. $pageRows = new Container(new YLayout(), OTHER, 1);
  185. $section =$sections->nextCourseSection();
  186. edit_section_detailsAction::viewSectionDetails($section);
  187. }
  188.  
  189. }
  190.  
  191. /*
  192. * offers a confirmation screen for deleting an entire offering
  193. */
  194. function confirmDeleteOffering($offering){
  195. $harmoni = Harmoni::instance();
  196. $url =$harmoni->request->mkURL();
  197. print "Do you really want to delete ".$offering->getDisplayName()."?<br />";
  198. print "<form action='".$url->write("furtherAction","edit_offering_detailsAction::deleteOffering")."' method='post'><input type='submit' value='Delete' /></form><input type='button' value='Cancel' onclick='history.back()' />";
  199. return;
  200. }
  201. /*
  202. * Handles the actual deletion of an offering
  203. */
  204. function deleteOffering($offering){
  205. //$cm = Services::getService("CourseManagement");
  206. $can =$offering->getCanonicalCourse();
  207. $can->deleteCourseOffering($offering->getId());
  208. $harmoni = Harmoni::instance();
  209. print "Offering deleted.<br />";
  210. $link1 = $harmoni->request->quickURL("coursemanagement", "coursesearch");
  211. print "<p><a href='".$link1."'>Go back to course search.</a></p>";
  212. $link2 = $harmoni->request->quickURL("coursemanagement", "createcourse");
  213. print "<p><a href='".$link2."'>Go back to creating courses.</a></p>";
  214. return;
  215. }
  216. function _printAgent($agent){
  217. if(!is_null($term)){
  218. //print "\n</table>";
  219. print "\n\t<tr>";
  220. print "\n<td><hr></td>";
  221. print "\n<td><hr></td>";
  222. print "\n\t\t</tr>";
  223. print "\n\t<tr>";
  224. print "\n\t\t<td><h4>";
  225. print $term->getDisplayName();
  226. print "</h4</td>";
  227. }else{
  228. print "\n\t<tr>";
  229. print "\n\t\t<td>";
  230. print "</td>";
  231. }
  232. $harmoni = Harmoni::instance();
  233. $id =$offering->getId();
  234. print "\n\t\t<td>";
  235. print "\n<a href='".$harmoni->request->quickURL("coursemanagement", "edit_offering_details", array("courseId"=>$id->getIdString()))."'>";
  236. print $offering->getDisplayName()."</a>";
  237. print "\n - <a href=\"Javascript:alert('"._("Id:").'\n\t'.addslashes($id->getIdString())."')\">"._("Id")."</a>";
  238. print "</td>";
  239. //print "\n\t\t<td>";
  240. //$term =$offering->getTerm();
  241. //print $term->getDisplayName();
  242. //print "</td>";
  243. print "\n\t</tr>";
  244. }
  245. function refreshOfferingDetails($offering){
  246. $term =$offering->getTerm();
  247. $termName = $term->getDisplayName();
  248. $year = substr($termName,strlen($termName)-2,2);
  249. $season = substr($termName,0,strlen($termName)-5);
  250. //print "Hmmm?";
  251. //print $termName;
  252. //print $season;
  253. //print $year;
  254. //print "Hmmm?";
  255. if($season === "Winter"){
  256. $seasonChar = 'w';
  257. }elseif($season === "Spring"){
  258. $seasonChar = 's';
  259. }elseif($season === "Summer"){
  260. $seasonChar = 'l';
  261. }elseif($season === "Fall"){
  262. $seasonChar = 'f';
  263. }else{
  264. //print "*'".$season."'*?";
  265. }
  266. $type = new Type("EnrollmentRecordType","edu.middlebury","LDAP");
  267. $distinguishedNameBase = "-".$seasonChar.$year.",OU=".$season.$year.",OU=Classes,OU=Groups,DC=middlebury,DC=edu";
  268. //print $distinguishedNameBase;
  269. $sections =$offering->getCourseSections();
  270. $am = Services::getService("AgentManager");
  271. $im = Services::getService("Id");
  272. while($sections->hasNextCourseSection()){
  273. $section = $sections->nextCourseSection();
  274. //print "'CN=".$section->getNumber().$distinguishedNameBase."'";
  275. $id = $im->getId("CN=".$section->getNumber().$distinguishedNameBase);
  276. $group =$am->getGroup($id);
  277. $agentIterator =$group->getMembers(false);
  278. while($agentIterator->hasNext()){
  279. $agent = $agentIterator->nextAgent();
  280. $agentId =$agent->getId();
  281. $dbManager = Services::getService("DatabaseManager");
  282. $query= new SelectQuery;
  283. $query->addTable('cm_enroll');
  284. $query->addWhere("fk_cm_section='".addslashes($section->_id->getIdString())."'");
  285. $query->addWhere("fk_student_id='".addslashes($agentId->getIdString())."'");
  286. //I don't need Id, but I need to select something for the query to work
  287. $query->addColumn('id');//@TODO select count instead
  288. $res=$dbManager->query($query);
  289. if($res->getNumberOfRows()==0){
  290. $section->addStudent($agentId, $p = new Type("EnrollmentStatusType","edu.middlebury","LDAP"));
  291. }
  292. //$section->addStudent($agentId,$type);
  293. }
  294. }
  295. }
  296. }
  297.  
  298. /*I know that this action has multiple furtherActions (subactions) but I thought it would help me modularize the design
  299. in editing and deleting a section (and seeing sections within an offering). I did separate out the editing of the
  300. section roster because that is a whole different process altogether.
  301. */

Documentation generated on Wed, 19 Sep 2007 10:22:57 -0400 by phpDocumentor 1.3.0RC3