PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/Layer-2__Business_logic/content/forms/Manage_Job_Offers_form.php

#
PHP | 168 lines | 103 code | 41 blank | 24 comment | 18 complexity | c3aa1e9654f7b99768b8330304eac8d3 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. // Authors: Davi Leal
  3. //
  4. // Copyright (C) 2006, 2007, 2008, 2009 Davi Leal <davi at leals dot com>
  5. //
  6. // This program is free software: you can redistribute it and/or modify it under
  7. // the terms of the GNU Affero General Public License as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied
  12. // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  13. // General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License along with this
  16. // program in the COPYING file. If not, see <http://www.gnu.org/licenses/>.
  17. require_once "../Layer-4__DBManager_etc/DB_Manager.php";
  18. // Methods take the values from the global $_POST[] array.
  19. class ManageJobOffersForm
  20. {
  21. private $manager;
  22. private $processingResult;
  23. private $data;
  24. function __construct()
  25. {
  26. $this->manager = new DBManager();
  27. $this->processingResult = '';
  28. }
  29. public function processForm()
  30. {
  31. // Check the log in state
  32. if ( $_SESSION['Logged'] == '1' )
  33. {
  34. if ( $_SESSION['LoginType'] != 'Person' && $_SESSION['LoginType'] != 'Cooperative' && $_SESSION['LoginType'] != 'Company' && $_SESSION['LoginType'] != 'non-profit Organization' )
  35. {
  36. $error = "<p>".gettext('To access this section you have to login first.')."</p>";
  37. throw new Exception($error,false);
  38. }
  39. }
  40. else
  41. {
  42. $error = "<p>".gettext('To access this section you have to login first.')."</p>";
  43. throw new Exception($error,false);
  44. }
  45. // Process each button event
  46. if ( $_POST['delete'] != '' )
  47. {
  48. if ( count($_POST['DeleteJobOffers']) >= 1 or count($_POST['CancelDonations']) >= 1 )
  49. {
  50. if ( $_GET['section'] == 'pledges' )
  51. {
  52. $this->manager->cancelSelectedDonations();
  53. }
  54. else
  55. {
  56. $this->manager->deleteSelectedJobOffers();
  57. }
  58. }
  59. }
  60. }
  61. public function printOutput()
  62. {
  63. $this->printManageJobOffersForm();
  64. }
  65. private function printManageJobOffersForm()
  66. {
  67. $smarty = new Smarty;
  68. switch ($_GET["section"]) {
  69. case "": case "offers":
  70. // Entries
  71. $result = $this->manager->getJobOffersForEntity(" AND ( J1_OfferType='Job offer' OR J1_OfferType='Job offer (post faster)' ) ORDER BY J1_OfferDate DESC ");
  72. $this->data['JobOfferId'] = $result[0];
  73. $this->data['OfferDate'] = $result[1];
  74. $this->data['ExpirationDate'] = $result[2];
  75. $this->data['Closed'] = $result[3];
  76. $this->data['VacancyTitle'] = isset($result[4]) ? $result[4] : '';
  77. // Meters
  78. $this->data['Visits'] = $result[6];
  79. $receivedMeter = array();
  80. $inProcessMeter = array();
  81. $ruledOutMeter = array();
  82. $finalistMeter = array();
  83. $selectedMeter = array();
  84. for ($i=0; $i < count($result[0]); $i++)
  85. {
  86. $receivedMeter[$i] = $this->manager->getApplicationsMeterForJobOffer( $result[0][$i], 'Received' );
  87. $inProcessMeter[$i] = $this->manager->getApplicationsMeterForJobOffer( $result[0][$i], 'In process' );
  88. $ruledOutMeter[$i] = $this->manager->getApplicationsMeterForJobOffer( $result[0][$i], 'Ruled out' );
  89. $finalistMeter[$i] = $this->manager->getApplicationsMeterForJobOffer( $result[0][$i], 'Finalist' );
  90. $selectedMeter[$i] = $this->manager->getApplicationsMeterForJobOffer( $result[0][$i], 'Selected' );
  91. }
  92. $smarty->assign('ReceivedMeter', $receivedMeter); //XXX: DELAYED: Set directly to $this->data['Meters'] the information got from getApplicationsMeterForJobOffer()
  93. $smarty->assign('InProcessMeter', $inProcessMeter);
  94. $smarty->assign('RuledOutMeter', $ruledOutMeter);
  95. $smarty->assign('FinalistMeter', $finalistMeter);
  96. $smarty->assign('SelectedMeter', $selectedMeter);
  97. break;
  98. case "pledges":
  99. // Donations
  100. $this->data['MyDonations'] = $this->manager->getMyDonations();
  101. // Entries
  102. for ($i=0; $i < count($this->data['MyDonations']['DonationPledgeGroupId']); $i++)
  103. {
  104. $this->data['Donations'][$i] = $this->manager->getDonationsForPledgeGroup( $this->data['MyDonations']['DonationPledgeGroupId'][$i] );
  105. $result = $this->manager->getJobOffer( $this->data['MyDonations']['DonationPledgeGroupId'][$i] );
  106. $this->data['OfferDate'][$i] = $result[1][0];
  107. $this->data['ExpirationDate'][$i] = $result[2][0];
  108. $this->data['VacancyTitle'][$i] = $result[60][0];
  109. }
  110. break;
  111. case "volunteers":
  112. // Entries
  113. $result = $this->manager->getJobOffersForEntity(" AND J1_OfferType='Looking for volunteers' ORDER BY J1_OfferDate DESC ");
  114. $this->data['JobOfferId'] = $result[0];
  115. $this->data['OfferDate'] = $result[1];
  116. $this->data['ExpirationDate'] = $result[2];
  117. $this->data['VacancyTitle'] = isset($result[4]) ? $result[4] : '';
  118. break;
  119. default:
  120. $error = "<p>".$_SERVER["REQUEST_URI"].": ".gettext('ERROR: Unexpected condition')."</p>";
  121. throw new Exception($error,false);
  122. }
  123. // Show
  124. $smarty->assign('data', $this->data);
  125. $smarty->display("Manage_Job_Offers_form.tpl");
  126. }
  127. }