home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 April / CMCD0404.ISO / Software / Freeware / Programare / dotproject / modules / projects / index.php < prev    next >
Encoding:
PHP Script  |  2004-01-26  |  5.9 KB  |  172 lines

  1. <?php  /* PROJECTS $Id: index.php,v 1.51 2004/01/26 18:56:38 kripper Exp $ */
  2. $AppUI->savePlace();
  3.  
  4. // load the companies class to retrieved denied companies
  5. require_once( $AppUI->getModuleClass( 'companies' ) );
  6.  
  7. // Let's update project status!
  8. if(isset($_GET["update_project_status"]) && isset($_GET["project_status"]) && isset($_GET["project_id"]) ){
  9.     $projects_id = $_GET["project_id"]; // This must be an array
  10.  
  11.     foreach($projects_id as $project_id){
  12.         $sql = "UPDATE projects
  13.                 SET project_status = '{$_GET['project_status']}'
  14.                 WHERE project_id   = '$project_id'";
  15.         db_exec( $sql );
  16.         echo db_error();
  17.     }
  18. }
  19. // End of project status update
  20.  
  21. // retrieve any state parameters
  22. if (isset( $_GET['tab'] )) {
  23.     $AppUI->setState( 'ProjIdxTab', $_GET['tab'] );
  24. }
  25. $tab = $AppUI->getState( 'ProjIdxTab' ) !== NULL ? $AppUI->getState( 'ProjIdxTab' ) : 0;
  26. $active = intval( !$AppUI->getState( 'ProjIdxTab' ) );
  27.  
  28. if (isset( $_POST['company_id'] )) {
  29.     $AppUI->setState( 'ProjIdxCompany', intval( $_POST['company_id'] ) );
  30. }
  31.  
  32. // BUG FIX: Selecting all companies didn't work
  33. // $company_id = $AppUI->getState( 'ProjIdxCompany' ) !== NULL ? $AppUI->getState( 'ProjIdxCompany' ) : $AppUI->user_company;
  34. $company_id = $AppUI->getState( 'ProjIdxCompany' );
  35.  
  36. if (isset( $_GET['orderby'] )) {
  37.     $AppUI->setState( 'ProjIdxOrderBy', $_GET['orderby'] );
  38. }
  39. $orderby = $AppUI->getState( 'ProjIdxOrderBy' ) ? $AppUI->getState( 'ProjIdxOrderBy' ) : 'project_end_date';
  40.  
  41. // get any records denied from viewing
  42. $obj = new CProject();
  43. $deny = $obj->getDeniedRecords( $AppUI->user_id );
  44.  
  45. // Task sum table
  46. // by Pablo Roca (pabloroca@mvps.org)
  47. // 16 August 2003
  48.  
  49. $sql = "
  50. CREATE TEMPORARY TABLE tasks_sum
  51.  SELECT task_project,
  52.  COUNT(distinct task_id) AS total_tasks,
  53.  SUM(task_duration*task_duration_type*task_percent_complete)/sum(task_duration*task_duration_type) as project_percent_complete
  54.  FROM tasks GROUP BY task_project
  55. ";
  56.  
  57. $tasks_sum = db_exec($sql);
  58.  
  59. // temporary My Tasks
  60. // by Pablo Roca (pabloroca@mvps.org)
  61. // 16 August 2003
  62. $sql = "
  63. CREATE TEMPORARY TABLE tasks_summy
  64.  SELECT task_project, COUNT(distinct task_id) AS my_tasks
  65.  FROM tasks 
  66.  WHERE task_owner = $AppUI->user_id GROUP BY task_project
  67. ";
  68.  
  69. $tasks_summy = db_exec($sql);
  70.  
  71. // retrieve list of records
  72. // modified for speed
  73. // by Pablo Roca (pabloroca@mvps.org)
  74. // 16 August 2003
  75. $sql = "
  76. SELECT
  77.     project_id, project_active, project_status, project_color_identifier, project_name, project_description,
  78.     project_start_date, project_end_date, project_actual_end_date,
  79.     project_color_identifier,
  80.     project_company, company_name, project_status,
  81.     tasks_sum.total_tasks,
  82.     tasks_summy.my_tasks,
  83.     tasks_sum.project_percent_complete,
  84.     user_username
  85. FROM permissions,projects
  86. LEFT JOIN companies ON company_id = projects.project_company
  87. LEFT JOIN users ON projects.project_owner = users.user_id
  88. LEFT JOIN tasks_sum ON projects.project_id = tasks_sum.task_project
  89. LEFT JOIN tasks_summy ON projects.project_id = tasks_summy.task_project
  90. WHERE permission_user = $AppUI->user_id
  91.     AND permission_value <> 0
  92.     AND (
  93.         (permission_grant_on = 'all')
  94.         OR (permission_grant_on = 'projects' AND permission_item = -1)
  95.         OR (permission_grant_on = 'projects' AND permission_item = project_id)
  96.         )"
  97. .(count($deny) > 0 ? "\nAND project_id NOT IN (" . implode( ',', $deny ) . ')' : '')
  98. .($company_id ? "\nAND project_company = $company_id" : '')
  99. ."
  100. GROUP BY project_id
  101. ORDER BY $orderby
  102. LIMIT 0,50
  103. ";
  104.  
  105. $projects = db_loadList( $sql );
  106.  
  107.  
  108. // get the list of permitted companies
  109. $obj = new CCompany();
  110. $companies = $obj->getAllowedRecords( $AppUI->user_id, 'company_id,company_name', 'company_name' );
  111. $companies = arrayMerge( array( '0'=>$AppUI->_('All') ), $companies );
  112.  
  113. // setup the title block
  114. $titleBlock = new CTitleBlock( 'Projects', 'applet3-48.png', $m, "$m.$a" );
  115. $titleBlock->addCell( $AppUI->_('Company') . ':' );
  116. $titleBlock->addCell(
  117.     arraySelect( $companies, 'company_id', 'onChange="document.pickCompany.submit()" class="text"', $company_id ), '',
  118.     '<form action="?m=projects" method="post" name="pickCompany">', '</form>'
  119. );
  120. $titleBlock->addCell();
  121. if ($canEdit) {
  122.     $titleBlock->addCell(
  123.         '<input type="submit" class="button" value="'.$AppUI->_('new project').'">', '',
  124.         '<form action="?m=projects&a=addedit" method="post">', '</form>'
  125.     );
  126. }
  127. $titleBlock->show();
  128.  
  129. $project_types = dPgetSysVal("ProjectStatus");
  130.  
  131. $fixed_project_type_file = array("In Progress" => "vw_idx_active",
  132.                                  "Complete"    => "vw_idx_complete",
  133.                                  "Archived"    => "vw_idx_archived");
  134. // we need to manually add Archived project type because this status is defined by 
  135. // other field (Active) in the project table, not project_status
  136. $project_types[] = "Archived";
  137.  
  138. // Only display the All option in tabbed view, in plain mode it would just repeat everything else
  139. // already in the page
  140. if ( $tab != -1 ) $project_types[] = "All";
  141.  
  142. /**
  143. * Now, we will figure out which vw_idx file are available
  144. * for each project type using the $fixed_project_type_file array 
  145. */
  146. $project_type_file = array();
  147.  
  148. foreach($project_types as $project_type){
  149.     $project_type = trim($project_type);
  150.     if(isset($fixed_project_type_file[$project_type])){
  151.         $project_file_type[$project_type] = $fixed_project_type_file[$project_type];
  152.     } else { // if there is no fixed vw_idx file, we will use vw_idx_proposed
  153.         $project_file_type[$project_type] = "vw_idx_proposed";
  154.     }
  155. }
  156.  
  157. $show_all_projects = false;
  158. if($tab == count($project_types)-1) $show_all_projects = true;
  159.  
  160. // tabbed information boxes
  161. $tabBox = new CTabBox( "?m=projects&orderby=$orderby", "{$AppUI->cfg['root_dir']}/modules/projects/", $tab );
  162. foreach($project_types as $project_type){
  163.     $project_type = trim($project_type);
  164.     $tabBox->add($project_file_type[$project_type], $project_type);
  165. }
  166. /*$tabBox->add( 'vw_idx_active'  , 'Active Projects' );
  167. $tabBox->add( 'vw_idx_proposed', 'Proposed Projects' );
  168. $tabBox->add( 'vw_idx_complete', 'Completed Projects' );
  169. $tabBox->add( 'vw_idx_archived', 'Archived Projects' );*/
  170. $tabBox->show();
  171. ?>
  172.