[ PHPXref.com ] [ Generated: Sun Jul 20 20:33:10 2008 ] [ TaskFreak! 0.1.4 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> project_edit.php (source)

   1  <?php
   2  /****************************************************************************\
   3  * TaskFreak!                                                                 *
   4  * multi user                                                                 *
   5  ******************************************************************************
   6  * Version: 0.1.4                                                             *
   7  * Release date: 18 May 2006                                                  *
   8  * Authors: Stan Ozier <taskfreak@gmail.com>                                  *
   9  * License:  http://www.gnu.org/licenses/gpl.txt (GPL)                        *
  10  ******************************************************************************
  11  * This file is part of "TaskFreak! multi user" program.                      *
  12  *                                                                            *
  13  * TaskFreak! multi user is free software; you can redistribute it and/or     *
  14  * modify it under the terms of the GNU General Public License as published   *
  15  * by the Free Software Foundation; either version 2 of the License, or (at   *  
  16  * your option) any later version.                                            *
  17  *                                                                            *
  18  * TaskFreak! multi user is distributed in the hope that it will be           *
  19  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
  21  * GNU General Public License for more details.                               *
  22  *                                                                            *
  23  * You should have received a copy of the GNU General Public License          *
  24  * along with this program; if not, write to the Free Software                *
  25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
  26  \****************************************************************************/
  27  
  28  include  '_common.php';
  29  
  30  /* --- INIT ----------------------------------------------------------- */
  31  
  32  $objEditItem = new Project();
  33  $objEditItem->initObjectProperties();
  34  
  35  $pTitle = 'Edit project';
  36  $pButton = 'Save changes';
  37  
  38  $pUserCanManage = false;    // can(not) manage project's member
  39  $pUserCanStatus = false;    // can(not) change project status
  40  $pUserCanEdit = false;      // can(not) edit project details
  41  $pUserCanDelete = false;    // can(not) delete project
  42  
  43  $pUserPosition = 0;         // current user's position
  44  
  45  
  46  /* --- LOAD PROJECT --------------------------------------------------- */
  47  
  48  if ($_REQUEST['id']) {
  49  
  50      // admin loads specific project
  51      $objEditItem->setUid($_REQUEST['id']);
  52      if (!$objEditItem->load()) {
  53          Tzn::redirect('project_list.php','ERROR:Project not found (error #424)');
  54      } else if ($objUser->checkLevel(8)) {
  55          // user can edit/manage any project (admin)
  56          $pUserCanManage = true;
  57          $pUserCanStatus = true;
  58          $pUserCanEdit = true;
  59          $pUserCanDelete = true;
  60          $pUserPosition = FRK_PROJECT_LEADER;
  61      } else {
  62          // check that user is leader or moderator
  63          $objMemberProject = new MemberProject();
  64          if ($objMemberProject->loadPosition($objEditItem->id,$objUser->id))
  65          {
  66              $pUserCanManage = $objMemberProject->checkRights(11);
  67              $pUserCanStatus = $objMemberProject->checkRights(12);
  68              $pUserCanEdit = $objMemberProject->checkRights(13);
  69              $pUserCanDelete = $objMemberProject->checkRights(14);
  70              $pUserPosition = $objMemberProject->position;
  71          } else if (!$objUser->checkLevel(10)) {
  72              Tzn::redirect('project_list.php','ERROR:'.$langMessage['not_found_or_denied']);
  73          }
  74      }
  75      
  76  } else {
  77  
  78      $pTitle = 'Create new project';
  79      $pButton = 'Create project';
  80  
  81      $pUserCanEdit=true;
  82      $pUserCanStatus=true;
  83  
  84  }
  85  
  86  /* --- MANAGE PROJECT'S MEMBERS -------------------------------------- */
  87  
  88  if ($pUserCanManage) {
  89  
  90      // --- remove user from project ---
  91      
  92      if ($_REQUEST['delete']) {
  93          $objMemberTeam = new MemberProject();
  94          $objMemberTeam->initObjectProperties();
  95          $objMemberTeam->project->id = $objEditItem->id;
  96          $objMemberTeam->member->setUid($_REQUEST['delete']);
  97          if ($objMemberTeam->delete()) {
  98              $pMessageEditStatus = 'Member removed from project!';
  99          } else {
 100              $pMessageError = 'Member can not be removed or has already been removed';
 101          }
 102      }
 103  
 104      // --- add new user to project ---
 105  
 106      if ($_POST['invite']) {
 107          $objMemberTeam = new MemberProject();
 108          $objMemberTeam->initObjectProperties();
 109          $objMemberTeam->project->id = $objEditItem->id;
 110          $objMemberTeam->member->setUid($_REQUEST['nuser']);
 111          $objMemberTeam->set('position',$_REQUEST['nposition']);
 112          if ($objMemberTeam->add()) {
 113              $pMessageEditStatus = 'Member successfully added to project';
 114          } else {
 115              $pMessageError = 'Member already belongs to project or is not available';
 116          }
 117      }
 118      
 119      // --- update position ---
 120      
 121      foreach ($_REQUEST as $key => $value) {
 122          if (ereg('^position-',$key)) {
 123              $id = intval(substr($key,9));
 124              if ($id != $objUser->id || $pUserIsAdmin) {
 125                  // can not change own position
 126                  $objMemberTeam = new MemberProject();
 127                  if ($objMemberTeam->loadPosition($objEditItem->id,$id))
 128                  {
 129                      if ($objMemberTeam->position != $value) {
 130                          // update database
 131                          $objMemberTeam->position = $value;
 132                          $objMemberTeam->getConnection();
 133                          $objMemberTeam->update('position');
 134                          $pMessageEditStatus = 'Member position(s) successfully updated';
 135                      }
 136                  }
 137              }
 138          }
 139      }
 140  
 141      if ($pMessageEditStatus) {
 142          Tzn::redirect('project_edit.php?id='.$objEditItem->id,$pMessageStatus);
 143      }
 144  
 145  }
 146  
 147  /* --- SAVE PROJECT INFO ---------------------------------------------- */
 148  
 149  if ($_POST['submit']) {
 150  
 151      // --- save general info ---
 152      
 153      if ($pUserCanEdit) {
 154  
 155          $objEditItem->setAuto($_POST);
 156              
 157          if ($objEditItem->check()) { // register form is valid
 158              
 159              if ($objEditItem->isLoaded()) {
 160  
 161                  // --- save project status ---
 162  
 163                  if ($pUserCanStatus && !$pMessageError && $_POST['status'] != $objEditItem->projectStatus->statusKey) {
 164  
 165                      $objEditItem->setStatus($_POST['status'],$objUser->id);
 166                      $objEditItem->update('projectStatus');
 167                      
 168                      $pMessageStatus = 'Project status updated!';
 169  
 170                  } else {
 171                      $pMessageStatus = 'Project details updated!';
 172                  }
 173              
 174                  $objEditItem->update();
 175              
 176              } else if ($objEditItem->add($_POST['status'],$objUser->id)) { // add in DB
 177  
 178                  $pMessageStatus = 'Project details updated!';
 179  
 180              }
 181  
 182          } else {
 183              $pMessageError = 'There are some errors in the form - Information not saved!';
 184          }
 185      }
 186  
 187  }
 188  
 189  // redirect on successful update
 190  if ($pMessageStatus) {
 191      Tzn::redirect('project_list.php',$pMessageStatus);
 192  }
 193  
 194  /* --- LOAD TEAM MEMBERS --------------------------------------------- */
 195  
 196  $objMemberList = new MemberProject();
 197  if ($objEditItem->isLoaded()) {
 198      $objMemberList->addWhere($objMemberList->gTable().'.projectId = '.$objEditItem->id);
 199      $objMemberList->addOrder('position DESC, firstName ASC');
 200      $objMemberList->loadList();
 201  }
 202  
 203  /* --- LOAD STATUS CHANGE HISTORY ------------------------------------- */
 204  
 205  $objStatusHistory = new ProjectStatus();
 206  if ($objEditItem->id) {
 207      $objStatusHistory->addWhere('projectId = '.$objEditItem->id);
 208      $objStatusHistory->addOrder('statusDate');
 209      $objStatusHistory->loadList();
 210  }
 211  
 212  /* --- LOAD OTHER USERS ----------------------------------------------- */
 213  
 214  $objOtherUserList = new Member();
 215  if ($objEditItem->isLoaded()) {
 216      $objOtherUserList->loadNonMemberList($objEditItem->id);
 217  }
 218  
 219  /* --- LOAD PROJECT STATUS -------------------------------------------- */
 220  
 221  $objStatusList = new ProjectStatusList();
 222  
 223  /* --- LOAD PROJECT POSITIONS ----------------------------------------- */
 224  
 225  $objPositionList = new ProjectPositionList($pUserPosition);
 226  
 227  /* --- HTML ----------------------------------------------------------- */
 228  
 229  $pJScript = 'team.js';
 230  
 231  include PRJ_INCLUDE_PATH.'html/header.php';
 232  ?>
 233  <div align="center">
 234    <div id="horiz" style="width:600px">
 235      <?php
 236      if ($pMessageError) {
 237          echo '<p class="box redish">'.$pMessageError.'</p>';
 238      }
 239      ?>
 240      <form action="project_edit.php" method="post">
 241      <?php $objEditItem->qHidden('id'); ?>
 242      <fieldset>
 243          <legend>
 244              Project information
 245          </legend>
 246          <?php
 247              if ($pUserCanEdit) {
 248                  echo '<p>'.$langForm['compulsory_legend'].'</p>';
 249              }
 250          ?>
 251          <table cellpadding="2" cellspacing="1" border="0" class="form">
 252              <tr>
 253                  <th width="100"><span class="compulsory"><?php echo $langProject['name']; ?></span>:</th>
 254                  <td>
 255                  <?php
 256                      if ($pUserCanEdit) {
 257                          $objEditItem->qText('name','','width:400px'); 
 258                      } else {
 259                          echo '<big>'.$objEditItem->get('name').'</big>';
 260                      }
 261                  ?>
 262                  </td>
 263              </tr>
 264              <tr valign="top">
 265                  <th><?php echo $langProject['description']; ?>:</th>
 266                  <td><?php
 267                      if ($pUserCanEdit) {
 268                          $objEditItem->qTextArea('description','','width:400px;height:60px');
 269                      } else {
 270                          $objEditItem->p('description','-');
 271                      }
 272                  ?></td>
 273              </tr>
 274              <tr>
 275                  <th><?php echo $langProject['status']; ?>:</th>
 276                  <td>
 277                  <?php
 278                      if ($pUserCanStatus) {
 279                          $objStatusList->qSelect('status',$objEditItem->projectStatus->statusKey,'','width:150px'); 
 280                          if ($objEditItem->id) {
 281                              echo ' <a href="javascript:tD(gE(\'status_history\'))" class="small">&gt; '.$langProject['project_history'].'</a>';
 282                          }
 283                      } else {
 284                  ?>
 285                      <a href="javascript:tD(gE('status_history'))"><?php echo $langProjectStatus[$objEditItem->projectStatus->statusKey]; ?></a>
 286                  <?php
 287                      }
 288                  ?></a>
 289                  </td>
 290              </tr>
 291          </table>
 292          <?php
 293              if ($objEditItem->id) {
 294          ?>
 295          <div id="status_history" style="display:none">
 296              <table cellpadding="2" cellspacing="1" border="0" width="60%" class="sheet">
 297                  <tr>
 298                      <th>Date</th>
 299                      <th>Status</th>
 300                      <th>User</th>
 301                  </tr>
 302          <?php
 303                  while ($objTmp=$objStatusHistory->rNext()) {
 304          ?>
 305                  <tr>
 306                      <td><?php echo $objTmp->getDte('statusDate','SHT'); ?></td>
 307                      <td><?php echo $objTmp->getStatus(); ?></td>
 308                      <td><?php echo $objTmp->member->getShortName(); ?></td>
 309                  </tr>
 310          <?php
 311                  }
 312          ?>
 313              </table>
 314          </div>
 315          <?php
 316              }
 317          ?>
 318          <div style="margin-top:12px">
 319          <?php
 320              if ($pUserCanEdit || $pUserCanStatus) {
 321          ?>
 322              <div style="float:left">
 323                  <input type="submit" name="submit" value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Reset form" />
 324              </div>
 325          <?php
 326              }
 327          ?>
 328              <input type="button" value="<?php echo $langButton['back']; ?>" onClick="window.location.href='project_list.php'" style="float:right"/>
 329              <div style="clear:both"></div>
 330          </div>
 331      </fieldset><br />
 332      </form>
 333  <?php
 334      if ($objEditItem->isLoaded()) {
 335  ?>
 336      <form action="project_edit.php" method="post">
 337      <fieldset>
 338          <legend><?php echo $langProject['members_legend']; ?></legend>
 339          <?php
 340              echo $objEditItem->qHidden('id');
 341  
 342              $objPositionList->pJSarray();
 343  
 344              if ($pUserCanManage && $objOtherUserList->rMore()) { 
 345                  // user has rights to edit/delete users
 346          ?>
 347          <p><img src="skins/<?php echo FRK_SKIN_FOLDER; ?>/images/bullet.png" /> <a href="javascript:tD(gE('invitation'))"><?php echo $langProject['user_add_legend']; ?></a></p>
 348          <div id="invitation" style="display:none">
 349              <fieldset style="margin-bottom: 20px">
 350                  <table cellspacing="0" cellpadding="3" border="0" class="form">
 351                      <tr>
 352                          <th><?php echo $langUser['user']; ?>:</th>
 353                          <td><?php $objOtherUserList->qSelect('nuser','getName()','',($objOtherUserList->rCount()==1)?'':'- select user -'); ?></td>
 354                      </tr>
 355                      <tr>
 356                          <th><?php echo $langProject['position']; ?>:</th>
 357                          <td><?php
 358                              $objPositionList->qSelect('nposition');
 359                          ?></td>
 360                      </tr>
 361                      <tr>
 362                          <th>&nbsp;</th>
 363                          <td><input type="submit" name="invite" value="<?php echo $langProject['user_add_button']; ?>" /></td>
 364                      </tr>
 365                  </table>
 366              </fieldset>
 367          </div>
 368          <?php
 369              }
 370          ?>
 371          <table cellspacing="0" cellpadding="3" border="0" width="100%" class="data">
 372              <thead>
 373                  <tr align="left">
 374                      <th width="<?php echo ($pUserCanManage)?'40':'45'; ?>%"><?php echo $langUser['name']; ?></th>
 375                      <th width="<?php echo ($pUserCanManage)?'35':'40'; ?>%"><?php echo $langUser['location']; ?></th>
 376                      <th width="15%"><?php echo $langProject['position']; ?></th>
 377                      <?php 
 378                          if ($pUserCanManage) { 
 379                              // user has rights to edit/delete users
 380                      ?>
 381                      <th width="10%"><?php echo $langProject['action']; ?></th>
 382                      <?php
 383                          }
 384                      ?>
 385                  </tr>
 386              </thead>
 387              <tbody>
 388          <?php
 389          $rowStyle = 'first';
 390          while ($objMemberTeam = $objMemberList->rNext()) {
 391              $rowStyle = ($rowStyle)?'':' class="odd"';
 392          ?>
 393                  <tr<?php echo $rowStyle; ?>>
 394                      <td><?php 
 395                          if ($objUser->checkLevel(1)) { 
 396                      ?>
 397                          <a href="user_details.php?id=<?php echo $objMemberTeam->member->id; ?>"<?php
 398                              if (!$objMemberTeam->position) {
 399                                  echo ' class="disabled"';
 400                              }
 401                          ?>><?php 
 402                              echo $objMemberTeam->member->getName();
 403                          ?></a><?php
 404                          } else {
 405                              echo $objMemberTeam->member->getName();
 406                          }
 407                      ?>
 408                      </td>
 409                      <td><?php echo $objMemberTeam->member->getLocation($arrCountry); ?></td>
 410                      <td id="pos-<?php echo $objMemberTeam->member->id; ?>"><?php $objMemberTeam->pPosition(); ?></td>
 411                      <?php 
 412                          if ($pUserCanManage) { 
 413                              // user has rights to edit/delete users
 414                      ?>
 415                      <td id="but-<?php echo $objMemberTeam->member->id; ?>">
 416                          <?php
 417                              if (($objUser->id != $objMemberTeam->member->id)
 418                                  && ($objMemberTeam->position < $pUserPosition))
 419                              { 
 420                          ?>
 421                          <a href="javascript:edit(<?php echo $objMemberTeam->member->id.','.$objMemberTeam->position.','.$pUserPosition ?>)"><img src="skins/<?php echo FRK_SKIN_FOLDER; ?>/images/b_edit.png" width="20" height="16" border="0" /></a>
 422                          <a href="project_edit.php?id=<?php echo $objEditItem->id; ?>&delete=<?php echo $objMemberTeam->member->id; ?>" onclick="return confirm('really remove this user from the team?');"><img src="skins/<?php echo FRK_SKIN_FOLDER; ?>/images/b_dele.png" width="20" height="16" border="0" /></a>
 423                          <?php
 424                              } else {
 425                                  echo '-';
 426                              }
 427                          ?>
 428                      </td>
 429                      <?php 
 430                          } 
 431                      ?>
 432                  </tr>
 433          <?php
 434          }
 435          ?>
 436              </tbody>
 437          </table>
 438      </fieldset>
 439      </form>
 440  <?php
 441      }
 442  ?>
 443    </div>
 444  </div>
 445  <?php
 446  include PRJ_INCLUDE_PATH.'html/footer.php';
 447  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]