00001 <?php if(!function_exists('startedIndexPhp')) { header("location:../index.php"); exit;}
00002 # streber - a php5 based project management system (c) 2005 Thomas Mann / thomas@pixtur.de
00003 # Distributed under the terms and conditions of the GPL as stated in lang/license.html
00004
00023 global $version_fields;
00024 $version_fields=array();
00025 addProjectItemFields(&$version_fields);
00026
00027 foreach(array(
00028 new FieldInternal(array( 'name'=>'id',
00029 'default'=>0,
00030 'in_db_object'=>1,
00031 'in_db_item'=>1,
00032 )),
00033 new FieldInternal(array( 'name'=>'project',
00034 'default'=>0,
00035 'in_db_object'=>1,
00036 'in_db_item'=>1,
00037 )),
00038 new FieldString(array( 'name'=>'name',
00039 'title'=>__('Version'),
00040 )),
00041
00042 new FieldInternal(array( 'name'=>'is_released',
00043 'default'=>0,
00044 )),
00045
00049 new FieldDatetime(array( 'name'=>'time_released',
00050 'title'=> __('Time Released'),
00051 'default'=>FINIT_NEVER
00052 )),
00053 new FieldText(array( 'name'=>'description',
00054 'title'=>__('Description'),
00055 )),
00056
00057 ) as $f) {
00058 $version_fields[$f->name]=$f;
00059 }
00060
00061
00062
00063
00067 class Version extends DbProjectItem
00068 {
00069 public $level; # level if child of parent-tasks
00070 public $type;
00071
00072
00073 function __construct ($id_or_array=NULL)
00074 {
00075 global $version_fields;
00076 $this->fields= &$version_fields;
00077
00078 parent::__construct($id_or_array);
00079 if(!$this->type) {
00080 $this->type= ITEM_VERSION;
00081 }
00082 }
00083
00084
00090 static function getById($id)
00091 {
00092 $e= new Version($id);
00093 if($e->id) {
00094 return $e;
00095 }
00096 return NULL;
00097 }
00098
00099
00107 static function getVisibleById($id)
00108 {
00109 if($e= Version::getById($id)) {
00110 if($p= Project::getById($e->project)) {
00111 if($p->validateViewItem($e)) {
00112 return $e;
00113 }
00114 }
00115 }
00116 return NULL;
00117 }
00118
00122 static function getEditableById($id)
00123 {
00124 if($e= Version::getById($id)) {
00125 if($p= Project::getById($e->project)) {
00126 if($p->validateEditItem($e)) {
00127 return $e;
00128 }
00129 }
00130 }
00131 return NULL;
00132 }
00133
00134
00135
00136
00143 static function &getVersions( $args=NULL)
00144 {
00145 global $auth;
00146 $prefix = confGet('DB_TABLE_PREFIX');
00147
00148 ### default params ###
00149 $project = NULL;
00150 $person = NULL;
00151 $order_by = 'v.time_released DESC';
00152 $visible_only = true; # use project rights settings
00153 $alive_only = true; # ignore deleted
00154 $task = NULL; # for a parent task?
00155 $date_min = NULL;
00156 $date_max = NULL;
00157
00158
00159 ### filter params ###
00160 if($args) {
00161 foreach($args as $key=>$value) {
00162 if(!isset($$key) && !is_null($$key) && !$$key==="") {
00163 trigger_error("unknown parameter",E_USER_NOTICE);
00164 }
00165 else {
00166 $$key= $value;
00167 }
00168 }
00169 }
00170
00171 $str_project= $project
00172 ? 'AND i.project=' . intval($project)
00173 : '';
00174
00175
00176 $str_project2= $project
00177 ? 'AND upp.project=' . intval($project)
00178 : '';
00179
00180
00181 $str_is_alive= $alive_only
00182 ? 'AND i.state=' . ITEM_STATE_OK
00183 : '';
00184
00185
00186 $str_date_min= $date_min
00187 ? "AND i.modified >= '" . asCleanString($date_min) . "'"
00188 : '';
00189
00190 $str_date_max= $date_max
00191 ? "AND i.modified <= ' ". asCleanString($date_max) . "'"
00192 : '';
00193
00194
00199 if($visible_only) {
00200 $str_query=
00201 "SELECT DISTINCT i.*, v.* from {$prefix}item i, {$prefix}version v, {$prefix}project p, {$prefix}projectperson upp
00202 WHERE
00203 i.type = '".ITEM_VERSION."'
00204 $str_project
00205 AND upp.person = {$auth->cur_user->id}
00206 $str_project2
00207
00208 $str_is_alive
00209 AND ( i.pub_level >= upp.level_view
00210 OR
00211 i.created_by = {$auth->cur_user->id}
00212 )
00213 AND i.project = p.id
00214
00215 AND i.id = v.id
00216 $str_date_max
00217 $str_date_min
00218
00219 ". getOrderByString($order_by)
00220 ;
00221 }
00222 ### show all ###
00223 else {
00224 $str_query=
00225 "SELECT i.*, f.* from {$prefix}item i, {$prefix}version v, {$prefix}project p
00226 WHERE
00227 i.type = '".ITEM_VERSION."'
00228 $str_project
00229 $str_is_alive
00230
00231 AND i.project = p.id
00232
00233 AND i.id = v.id
00234 $str_date_max
00235 $str_date_min
00236
00237 ". getOrderByString($order_by)
00238 ;
00239 }
00240
00241 $dbh = new DB_Mysql;
00242 $sth= $dbh->prepare($str_query);
00243
00244 $sth->execute("",1);
00245 $tmp=$sth->fetchall_assoc();
00246 $files=array();
00247 foreach($tmp as $t) {
00248 $version=new Version($t);
00249 $versions[]=$version;
00250 }
00251 return $versions;
00252 }
00253
00254
00255
00256 function getProject()
00257 {
00258 require_once("db/class_project.inc.php");
00259 if(!$this->project) {
00260 #trigger_error("Task:getProject. project-id not set",E_USER_WARNING);
00261 return NULL;
00262 }
00263 $project= Project::getById($this->project);
00264 return $project;
00265 }
00266
00267
00268 function getProjectLink()
00269 {
00270 if($project= $this->getProject()) {
00271 return "<nobr>".$project->getLink().'</nobr>';
00272 }
00273 else {
00274 return NULL;
00275 }
00276 }
00277 }
00278
00279 ?>