From: <sy...@us...> - 2006-01-05 17:16:48
|
Update of /cvsroot/tikiwiki/tiki/lib/wiki-plugins In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5518/lib/wiki-plugins Modified Files: wikiplugin_tracker.php Log Message: Instant-Auto-Merge from BRANCH-1-9 to HEAD Index: wikiplugin_tracker.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/wiki-plugins/wikiplugin_tracker.php,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- wikiplugin_tracker.php 16 Oct 2005 14:35:10 -0000 1.24 +++ wikiplugin_tracker.php 5 Jan 2006 17:16:38 -0000 1.25 @@ -30,32 +30,47 @@ if (!isset($showmandatory)) { $showmandatory = 'y'; } + $tracker = $tikilib->get_tracker($trackerId); + + if (!isset($_REQUEST["ok"]) || $_REQUEST["ok"] == "n") { - if ($tracker) { - include_once('lib/trackers/trackerlib.php'); - global $notificationlib; include_once('lib/notifications/notificationlib.php'); - $tracker = array_merge($tracker,$trklib->get_tracker_options($trackerId)); - $flds = $trklib->list_tracker_fields($trackerId,0,-1,"position_asc",""); - $back = ''; - $bad = array(); - $embeddedId = false; - $onemandatory = false; + $field_errors = array('err_mandatory'=>array(), 'err_value'=>array()); + + if ($tracker) { + include_once('lib/trackers/trackerlib.php'); + global $notificationlib; include_once('lib/notifications/notificationlib.php'); + $tracker = array_merge($tracker,$trklib->get_tracker_options($trackerId)); + $flds = $trklib->list_tracker_fields($trackerId,0,-1,"position_asc",""); + $back = ''; + $bad = array(); + $embeddedId = false; + $onemandatory = false; + $full_fields = array(); - if (isset($_REQUEST['trackit']) and $_REQUEST['trackit'] == $trackerId) { - foreach ($flds['data'] as $fl) { - if ($fl['isMandatory'] == 'y') { - if (!isset($_REQUEST['track']["{$fl['fieldId']}"]) or !$_REQUEST['track']["{$fl['fieldId']}"]) { - $bad[] = $fl['name']; + if (isset($_REQUEST['trackit']) and $_REQUEST['trackit'] == $trackerId) { + $cpt = 0; + foreach ($flds['data'] as $fl) { + + // store value to display it later if form + // isn't fully filled. + if(isset($_REQUEST['track'][$fl['fieldId']])) { + $flds['data'][$cpt]['value'] = $_REQUEST['track'][$fl['fieldId']]; } + else { + $flds['data'][$cpt]['value'] = ''; + } + $full_fields[$fl['fieldId']] = $fl; + + if ($embedded == 'y' and $fl['name'] == 'page') { + $embeddedId = $fl['fieldId']; + } + $cpt++; } - if ($embedded == 'y' and $fl['name'] == 'page') { - $embeddedId = $fl['fieldId']; - } - } - if (count($bad) == 0) { + foreach ($_REQUEST['track'] as $fld=>$val) { - $ins_fields["data"][] = array('fieldId' => $fld, 'value' => $val, 'type' => 1); + //$ins_fields["data"][] = array('fieldId' => $fld, 'value' => $val, 'type' => 1); + $ins_fields["data"][] = array_merge(array('value' => $val), $full_fields[$fld]); } if (isset($_REQUEST['authorfieldid']) and $_REQUEST['authorfieldid']) { $ins_fields["data"][] = array('fieldId' => $_REQUEST['authorfieldid'], 'value' => $user, 'type' => 'u', 'options' => 1); @@ -66,154 +81,196 @@ if ($embedded == 'y') { $ins_fields["data"][] = array('fieldId' => $embeddedId, 'value' => $_REQUEST['page']); } - $rid = $trklib->replace_item($trackerId,0,$ins_fields,$tracker['newItemStatus']); - header("Location: tiki-index.php?page=".urlencode($page)."&ok=y"); - die; - // return "<div>$data</div>"; + + // Check field values for each type and presence of mandatory ones + $field_errors = $trklib->check_field_values($ins_fields); + + // values are OK, then lets add a new item + if( count($field_errors['err_mandatory']) == 0 && count($field_errors['err_value']) == 0 ) { + $rid = $trklib->replace_item($trackerId,0,$ins_fields,$tracker['newItemStatus']); + header("Location: tiki-index.php?page=".urlencode($page)."&ok=y"); + die; + // return "<div>$data</div>"; + } + } + // initialize fields with blank values + else { + for($i = 0; $i < count($flds['data']); $i++) { + $flds['data'][$i]['value'] = ''; + } } - } - $optional = array(); - if (isset($fields)) { - $outf = array(); - $fl = split(":",$fields); - foreach ($fl as $l) { - if (substr($l,0,1) == '-') { - $l = substr($l,1); - $optional[] = $l; + $optional = array(); + if (isset($fields)) { + $outf = array(); + $fl = split(":",$fields); + + foreach ($fl as $l) { + if (substr($l,0,1) == '-') { + $l = substr($l,1); + $optional[] = $l; + } + $outf[] = $l; } - $outf[] = $l; } - } - if (count($bad)) { - $back.= "<div class='simplebox'>".tra("You need to supply information for : ").implode(', ',$bad)."</div>"; - } - $back.= '~np~<form><input type="hidden" name="trackit" value="'.$trackerId.'" />'; - $back.= '<input type="hidden" name="page" value="'.$_REQUEST["page"].'" />'; - $back.= '<input type="hidden" name="refresh" value="1" />'; - if ($showtitle == 'y') { - $back.= '<div class="titlebar">'.$tracker["name"].'</div>'; - } - if ($showdesc == 'y') { - $back.= '<div class="wikitext">'.$tracker["description"].'</div><br />'; - } - $back.= '<table>'; - foreach ($flds['data'] as $f) { - if ($f['type'] == 'u' and $f['options'] == '1') { - $back.= '<input type="hidden" name="authorfieldid" value="'.$f['fieldId'].'" />'; + + // Display warnings when needed + if(count($field_errors['err_mandatory']) > 0) { + $back.= '<div class="simplebox highlight">'; + $back.= tra('Following mandatory fields are missing').' :<br/>'; + $coma_cpt = count($field_errors['err_mandatory']); + foreach($field_errors['err_mandatory'] as $f) { + $back.= $f['name']; + $back.= --$coma_cpt > 0 ? ', ' : ''; + } + $back.= '</div><br />'; } - if ($f['type'] == 'g' and $f['options'] == '1') { - $back.= '<input type="hidden" name="authorgroupfieldid" value="'.$f['fieldId'].'" />'; + + if(count($field_errors['err_value']) > 0) { + $back.= '<div class="simplebox highlight">'; + $back.= tra('Following fields are incorrect').' :<br/>'; + $coma_cpt = count($field_errors['err_value']); + foreach($field_errors['err_value'] as $f) { + $back.= $f['name']; + $back.= --$coma_cpt > 0 ? ', ' : ''; + } + $back.= '</div><br />'; } - if (in_array($f['fieldId'],$outf)) { - if (in_array($f['fieldId'],$optional)) { - $f['name'] = "<i>".$f['name']."</i>"; + + $back.= '~np~<form><input type="hidden" name="trackit" value="'.$trackerId.'" />'; + $back.= '<input type="hidden" name="page" value="'.$_REQUEST["page"].'" />'; + $back.= '<input type="hidden" name="refresh" value="1" />'; + if ($showtitle == 'y') { + $back.= '<div class="titlebar">'.$tracker["name"].'</div>'; + } + if ($showdesc == 'y') { + $back.= '<div class="wikitext">'.$tracker["description"].'</div><br />'; + } + + // Loop on tracker fields and display form + $back.= '<table>'; + foreach ($flds['data'] as $f) { + if ($f['type'] == 'u' and $f['options'] == '1') { + $back.= '<input type="hidden" name="authorfieldid" value="'.$f['fieldId'].'" />'; } - if ($f['type'] == 't' or $f['type'] == 'n' and $f["fieldId"] != $embeddedId or $f['type'] == 'm') { - $back.= "<tr><td>".$f['name']; - if ($f['isMandatory'] == 'y') { - $back.= " <b>*</b> "; - $onemandatory = true; - } - $back.= "</td><td>"; - $back.= '<input type="text" size="30" name="track['.$f["fieldId"].']" value=""'; - if (isset($f['options_array'][1])) { - $back.= 'size="'.$f['options_array'][1].'" maxlength="'.$f['options_array'][1].'"'; - } else { - $back.= 'size="30"'; - } - $back.= '/>'; - } elseif ($f['type'] == 'r') { - $list = $trklib->get_all_items($f['options_array'][0],$f['options_array'][1],'o'); - $back.= "<tr><td>".$f['name']; - if ($f['isMandatory'] == 'y') { - $back.= " <b>*</b> "; - $onemandatory = true; - } - $back.= "</td><td>"; - $back.= '<select name="track['.$f["fieldId"].']">'; - $back.= '<option value=""></option>'; - foreach ($list as $key=>$item) { - $back.= '<option value="'.$item.'">'.$item.'</option>'; - } - $back.= "</select>"; - } elseif ($f['type'] == 'a') { - $back.= "<tr><td>".$f['name']; - if ($f['isMandatory'] == 'y') { - $back.= " <b>*</b> "; - $onemandatory = true; - } - $back.= "</td><td>"; - if( isset($f['options_array'][1]) ) { - $back.= '<textarea cols='.$f['options_array'][1].' rows='.$f['options_array'][2].' name="track['.$f["fieldId"].']" wrap="soft"></textarea>'; - } else { - $back.= '<textarea cols="29" rows="7" name="track['.$f["fieldId"].']" wrap="soft"></textarea>'; + if ($f['type'] == 'g' and $f['options'] == '1') { + $back.= '<input type="hidden" name="authorgroupfieldid" value="'.$f['fieldId'].'" />'; + } + if (in_array($f['fieldId'],$outf)) { + if (in_array($f['fieldId'],$optional)) { + $f['name'] = "<i>".$f['name']."</i>"; } - } elseif ($f['type'] == 'd' or $f['type'] == 'u' or $f['type'] == 'g' or $f['type'] == 'r') { - if ($f['type'] == 'd') { - $list = split(',',$f['options']); - } elseif ($f['type'] == 'u') { - if ($f['options'] == 1 or $f['options'] == 2) { - $list = false; + if ($f['type'] == 't' or $f['type'] == 'n' and $f["fieldId"] != $embeddedId or $f['type'] == 'm') { + $back.= "<tr><td>".$f['name']; + if ($f['isMandatory'] == 'y') { + $back.= " <b>*</b> "; + $onemandatory = true; + } + $back.= "</td><td>"; + $back.= '<input type="text" size="30" name="track['.$f["fieldId"].']" value="'.$f['value'].'"'; + if (isset($f['options_array'][1])) { + $back.= 'size="'.$f['options_array'][1].'" maxlength="'.$f['options_array'][1].'"'; } else { - $list = $userlib->list_all_users(); + $back.= 'size="30"'; } - } elseif ($f['type'] == 'g') { - $list = $userlib->list_all_groups(); - } - if ($list) { + $back.= '/>'; + } elseif ($f['type'] == 'r') { + $list = $trklib->get_all_items($f['options_array'][0],$f['options_array'][1],'o'); $back.= "<tr><td>".$f['name']; - if ($showmandatory == 'y' and $f['isMandatory'] == 'y') { + if ($f['isMandatory'] == 'y') { $back.= " <b>*</b> "; $onemandatory = true; } $back.= "</td><td>"; $back.= '<select name="track['.$f["fieldId"].']">'; - foreach ($list as $item) { - $back.= '<option value="'.$item.'">'.$item.'</option>'; + $back.= '<option value=""></option>'; + foreach ($list as $key=>$item) { + $selected = $f['value'] == $item ? 'selected="selected"' : ''; + $back.= '<option value="'.$item.'" '.$selected.'>'.$item.'</option>'; } $back.= "</select>"; + } elseif ($f['type'] == 'a') { + $back.= "<tr><td>".$f['name']; + if ($f['isMandatory'] == 'y') { + $back.= " <b>*</b> "; + $onemandatory = true; + } + $back.= "</td><td>"; + if( isset($f['options_array'][1]) ) { + $back.= '<textarea cols='.$f['options_array'][1].' rows='.$f['options_array'][2].' name="track['.$f["fieldId"].']" wrap="soft">'.$f['value'].'</textarea>'; + } else { + $back.= '<textarea cols="29" rows="7" name="track['.$f["fieldId"].']" wrap="soft">'.$f['value'].'</textarea>'; + } + } elseif ($f['type'] == 'd' or $f['type'] == 'u' or $f['type'] == 'g' or $f['type'] == 'r') { + if ($f['type'] == 'd') { + $list = split(',',$f['options']); + } elseif ($f['type'] == 'u') { + if ($f['options'] == 1 or $f['options'] == 2) { + $list = false; + } else { + $list = $userlib->list_all_users(); + } + } elseif ($f['type'] == 'g') { + $list = $userlib->list_all_groups(); + } + if ($list) { + $back.= "<tr><td>".$f['name']; + if ($showmandatory == 'y' and $f['isMandatory'] == 'y') { + $back.= " <b>*</b> "; + $onemandatory = true; + } + $back.= "</td><td>"; + $back.= '<select name="track['.$f["fieldId"].']">'; + foreach ($list as $item) { + $selected = $f['value'] == $item ? 'selected="selected"' : ''; + $back.= '<option value="'.$item.'" '.$selected.'>'.$item.'</option>'; + } + $back.= "</select>"; + } else { + $back.= '<input type="hidden" name="track['.$f["fieldId"].']" value="'.$user.'" />'; + } + } elseif ($f['type'] == 'h') { + $back .= "</td></tr></table><h2>".$f['name']."</h2><table><tr><td>"; + } elseif ($f['type'] == 'e') { + $back .="<tr><td>".$f['name']; + if ($f['isMandatory'] == 'y') { + $back.= " <b>*</b> "; + $onemandatory = true; + } + $back .= "</td><td>"; + $k = $f["options_array"][0]; + global $categlib; include_once('lib/categories/categlib.php'); + $cats = $categlib->get_child_categories($k); + foreach ($cats as $cat) { + $checked = $f['value'] == $cat['categId'] ? 'checked="checked"' : ''; + $back .= '<input type="checkbox" name="track['.$f["fieldId"].']" value="'.$cat["categId"].'" '.$checked.'>'.$cat['name'].'</input>'; + } + } elseif ($f['type'] == 'c') { + $back .="<tr><td>".$f['name']; + if ($f['isMandatory'] == 'y') { + $back.= " <b>*</b> "; + $onemandatory = true; + } + $checked = $f['value'] == 'y' ? 'checked="checked"' : ''; + $back .= '</td><td><input type="checkbox" name="track['.$f["fieldId"].']" value="y" '.$checked.'/>'; } else { - $back.= '<input type="hidden" name="track['.$f["fieldId"].']" value="'.$user.'" />'; - } - } elseif ($f['type'] == 'h') { - $back .= "</td></tr></table><h2>".$f['name']."</h2><table><tr><td>"; - } elseif ($f['type'] == 'e') { - $back .="<tr><td>".$f['name']; - if ($f['isMandatory'] == 'y') { - $back.= " <b>*</b> "; - $onemandatory = true; - } - $back .= "</td><td>"; - $k = $f["options_array"][0]; - global $categlib; include_once('lib/categories/categlib.php'); - $cats = $categlib->get_child_categories($k); - foreach ($cats as $cat) { - $back .= '<input type="checkbox" name="track['.$f["fieldId"].']" value="'.$cat["categId"].'">'.$cat['name'].'</input>'; - } - } elseif ($f['type'] == 'c') { - $back .="<tr><td>".$f['name']; - if ($f['isMandatory'] == 'y') { - $back.= " <b>*</b> "; - $onemandatory = true; } - $back .= '</td><td><input type="checkbox" name="track['.$f["fieldId"].']" value="y" />'; - } else { + $back.= "</td></tr>"; } - $back.= "</td></tr>"; } + $back.= "<tr><td></td><td><input type='submit' name='action' value='".$action."'>"; + if ($showmandatory == 'y' and $onemandatory) { + $back.= "<br /><i>".tra("Fields marked with a * are mandatory.")."</i>"; + } + $back.= "</td></tr>"; + $back.= "</table>"; + $back.= "</form>~/np~"; + } else { + $back = "No such id in trackers."; } - $back.= "<tr><td></td><td><input type='submit' name='action' value='".$action."'>"; - if ($showmandatory == 'y' and $onemandatory) { - $back.= "<br /><i>".tra("Fields marked with a * are mandatory.")."</i>"; - } - $back.= "</td></tr>"; - $back.= "</table>"; - $back.= "</form>~/np~"; - } else { - $back = "No such id in trackers."; + return $back; } - if (isset($_REQUEST["ok"]) && $_REQUEST["ok"] == "y") { + else { $back = ''; if ($showtitle == 'y') { $back.= '<div class="titlebar">'.$tracker["name"].'</div>'; @@ -224,8 +281,6 @@ $back.= '<div>'.$data.'</div>'; return $back; } - else - return $back; } ?> |