protected function extractDataFromResult($res, $ids, $column)
 {
     $data = array();
     if ($res && db_numrows($res)) {
         db_reset_result($res);
         while ($d = db_fetch_array($res)) {
             if (!isset($data[$d['day']])) {
                 $data[$d['day']] = array();
                 foreach ($ids as $id) {
                     $data[$d['day']][$id] = 0;
                 }
             }
             $data[$d['day']][$d['id']] += $d[$column];
         }
         ksort($data);
         $previous = array();
         foreach ($data as $k => $d) {
             if (count($previous)) {
                 foreach ($d as $id => $v) {
                     if ($v == 0 && $previous[$id]) {
                         $data[$k][$id] = $previous[$id];
                     }
                 }
             }
             $previous = $data[$k];
         }
     }
     return $data;
 }
Ejemplo n.º 2
0
function db_query_params($sql, $params)
{
    global $conn;
    $dar = $conn->query($sql, $params);
    $GLOBALS['db_qhandle'] = $dar->getResult();
    if (db_numrows($GLOBALS['db_qhandle'])) {
        db_reset_result($GLOBALS['db_qhandle']);
    }
    return $GLOBALS['db_qhandle'];
}
Ejemplo n.º 3
0
 /**
  *	Group - Group object constructor - use group_get_object() to instantiate.
  *
  *	@param	int		Required - group_id of the group you want to instantiate.
  *	@param	int		Database result from select query OR associative array of all columns.
  */
 function Group($id = false, $res = false)
 {
     $this->Error();
     if (!$id) {
         //setting up an empty object
         //probably going to call create()
         return true;
     }
     if (!$res) {
         if (!$this->fetchData($id)) {
             return false;
         }
     } else {
         //
         //	Assoc array was passed in
         //
         if (is_array($res)) {
             $this->data_array =& $res;
         } else {
             if (db_numrows($res) < 1) {
                 //function in class we extended
                 $this->setError('Group Not Found');
                 $this->data_array = array();
                 return false;
             } else {
                 //set up an associative array for use by other functions
                 db_reset_result($res);
                 $this->data_array =& db_fetch_array($res);
             }
         }
     }
     $systemGroups = array(GROUP_IS_NEWS, GROUP_IS_STATS, GROUP_IS_PEER_RATINGS);
     if (!$this->isPublic() && !in_array($id, $systemGroups)) {
         $perm =& $this->getPermission(session_get_user());
         if (!$perm || !is_object($perm) || !$perm->isMember()) {
             $this->setError(_('Permission denied'), ERROR__PERMISSION_DENIED_ERROR);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  *	GFUser($id,$res) - CONSTRUCTOR - GENERALLY DON'T USE THIS
  *
  *	instead use the user_get_object() function call
  *
  *	@param	int		The user_id
  *	@param	int		The database result set OR array of data
  */
 function GFUser($id = false, $res = false)
 {
     $this->Error();
     if (!$id) {
         //setting up an empty object
         //probably going to call create()
         return true;
     }
     if (!$res) {
         $this->fetchData($id);
     } else {
         if (is_array($res)) {
             $this->data_array =& $res;
         } elseif (db_numrows($res) < 1) {
             //function in class we extended
             $this->setError('User Not Found');
             $this->data_array = array();
             return false;
         } else {
             //set up an associative array for use by other functions
             db_reset_result($res);
             $this->data_array = db_fetch_array($res);
         }
     }
     $this->is_super_user = false;
     $this->is_logged_in = false;
     return true;
 }
Ejemplo n.º 5
0
 /**
  * 
  *  Returns a select box populated with field values for this project
  *  if box_name is given then impose this name in the select box
  *  of the  HTML form otherwise use the field_name)
  * 
  *  @param box_name: the selectbox name
  *  @param group_artifact_id: the artifact type id
  *  @param checked,show_none,text_none,show_any,text_any: values used by html_build_select_box function
  *  @param display: to manage the display of the selectBox: In case of RO it is not dispalyed
  *  
  *	@return	string
  */
 function fieldBox($box_name = '', $group_artifact_id, $checked = false, $show_none = false, $text_none = 0, $show_any = false, $text_any = 0, $show_unchanged = false, $text_unchanged = 0, $display = true)
 {
     global $Language;
     $hp = Codendi_HTMLPurifier::instance();
     if (!$text_none) {
         $text_none = $Language->getText('global', 'none');
     }
     if (!$text_any) {
         $text_any = $Language->getText('global', 'any');
     }
     if (!$text_unchanged) {
         $text_unchanged = $Language->getText('global', 'unchanged');
     }
     if (!$group_artifact_id) {
         return $Language->getText('tracker_include_field', 'error_no_atid');
     } else {
         $result = $this->getFieldPredefinedValues($group_artifact_id, $checked, false, true, false, true);
         $array_values = array();
         // $array_values is used to write javascript field dependencies
         // getFieldPredefinedValues doesn't always return the none value and the any value for the binded fields
         // so we add them everytime by precaution.
         if ($show_any) {
             $array_values[] = array(0, $text_any);
         }
         if ($show_none) {
             $array_values[] = array(100, $text_none);
         }
         if ($show_unchanged) {
             $array_values[] = array($text_unchanged, $text_unchanged);
         }
         while ($row = db_fetch_array($result)) {
             $array_values[] = $row;
         }
         if (db_numrows($result) > 0) {
             db_reset_result($result);
         }
         if ($box_name == '') {
             $box_name = $this->field_name;
         }
         $output = '';
         if ($display) {
             $output .= html_build_select_box($result, $box_name, $checked, $show_none, $text_none, $show_any, $text_any, $show_unchanged, $text_unchanged);
         }
         if ($this->isJavascriptEnabled) {
             $output .= '<script type="text/javascript">';
             $output .= "\ncodendi.tracker.fields.add('" . (int) $this->getID() . "', '" . $hp->purify($this->getName(), CODENDI_PURIFIER_JS_QUOTE) . "', '" . $hp->purify(SimpleSanitizer::unsanitize($this->getLabel()), CODENDI_PURIFIER_JS_QUOTE) . "')";
             $output .= $this->_getValuesAsJavascript($array_values, $checked, $text_unchanged);
             $output .= ';';
             $output .= "\n</script>";
         }
         return $output;
     }
 }