Пример #1
0
function format_value($value, $type_hint = FALSE)
{
    if (is_null($value) || $value === '') {
        return '<span class="blank">(blank)</span>';
    } else {
        if (is_array($value)) {
            // dates or checkboxes
            if (count($value) == 0) {
                return '<span class="blank">(blank)</span>';
            }
            $str_val = '';
            $delim = '';
            foreach ($value as $el) {
                $str_val = $str_val . $delim . format_value($el);
                $delim = '<br/>';
            }
            return $str_val;
        } else {
            if (is_string($value)) {
                return nl2br(htmlspecialchars($value));
            } else {
                echo "(Warning: Unknown data type)";
                return format_value("{$value}");
            }
        }
    }
}
Пример #2
0
</td>
                </tr>
            <?php 
    }
    ?>
                
            <tr class="desk-data">
                <td>Totals</td>
                <?php 
    $desk_score = 0;
    ?>
                <?php 
    foreach ($metrics as $metric) {
        ?>
                    <?php 
        $value = format_value($metric, $data->desk_data[$desk]['metrics'][$metric]);
        ?>
                    <?php 
        $desk_score += $data->desk_data[$desk]['scores'][$metric];
        ?>
                    <td class='<?php 
        echo $metric;
        ?>
-metric'><?php 
        echo $value;
        ?>
</td>
                    <td class="score"><?php 
        echo round($data->desk_data[$desk]['scores'][$metric], 1);
        ?>
</td>
  * Check if the directory exists.
  * If it does, stop unless cachelevel= 0
  * If it doesn't, make it.
  * Initialize files to write.
  */
 if (!is_dir("individuals/{$reporting_period}/{$desk}/{$reporter['attributes']['author_name']}")) {
     mkdir("individuals/{$reporting_period}/{$desk}/{$reporter['attributes']['author_name']}", 0777) or die('couldnt make directory');
 }
 $handle = fopen("individuals/{$reporting_period}/{$desk}/{$reporter['attributes']['author_name']}/{$reporter['attributes']['author_name']}_{$reporting_period}_SCORES.tsv", "w") or die("Cannot open the file for scores");
 /**
  * Scores sheet
  */
 $scores_data = "metric\t individual value\t individual score\t desk score\r\n";
 // foreach($reporter['metrics'] as $metric => $value) {
 foreach ($metrics as $metric) {
     $value = format_value($metric, $reporter['metrics'][$metric]);
     $scores_data .= ucwords(str_replace("_", " ", $metric)) . "\t \"" . $value . "\"\t " . round($reporter['scores'][$metric], 1) . "\t " . round($data['desk_data'][$desk]['scores'][$metric], 1) . "\r\n";
 }
 //reporter metrics
 //Total score
 $scores_data .= "BDN score\t --\t " . round(calculate_total_score($metrics, $reporter['scores']), 1) . "\t " . round(calculate_total_score($metrics, $data['desk_data'][$desk]['scores']), 1);
 fwrite($handle, $scores_data);
 fclose($handle);
 /**
  * Stories sheet
  */
 $handle = fopen("individuals/{$reporting_period}/{$desk}/{$reporter['attributes']['author_name']}/{$reporter['attributes']['author_name']}_{$reporting_period}_STORIES.tsv", "w") or die("Cannot open the file for stories");
 $stories_data = "title\t wp_id\t time\t day\t date\t " . "story_importance\t " . "word_count\t " . "facebook shares\t facebook likes\t facebook comments\t " . "pageviews\t " . "timeOnPage\t " . "exits\t " . "avgTimeOnPage\t " . "StartReading\t " . "ContentBottom\t " . "completion_rate\t " . "home_run\r\n";
 foreach ($reporter['stories'] as $wp_id => $story) {
     $home_run = $story['home_run'] ? "Yes" : "No";
     $stories_data .= "\"" . addslashes($story['title']) . "\" \t " . $wp_id . "\t " . date("G:i", strtotime($story['date'])) . "\t " . date("l", strtotime($story['date'])) . "\t " . date("Y-m-d", strtotime($story['date'])) . "\t " . $story['story_importance'] . "\t " . $story['word_count'] . "\t " . $story['facebook']['share_count'] . "\t " . $story['facebook']['like_count'] . "\t " . $story['facebook']['comment_count'] . "\t " . $story['pageviews'] . "\t " . $story['timeOnPage'] . "\t " . $story['exits'] . "\t " . $story['avgTimeOnPage'] . "\t " . $story['StartReading'] . "\t " . $story['ContentBottom'] . "\t " . $story['completion_rate'] . "\t " . $home_run . "\r\n";
Пример #4
0
function do_table($w, $values0, $values1, $values2, $values3, $values4, $ignore, $format_value, $format_word, $get_link = NULL, $extras = NULL, $optimization = 0)
{
    ?>
<div class="scrollable"><?php 
    if ($values1 and !$values2 and !$values3 and !$values4 and !$values0) {
        ?>
<table class="text-center inflection inflection-small" id="word<?php 
        echo $w->id();
        ?>
_forms"><?php 
        foreach ($values1[false] as $_1) {
            ?>
<tr><th><?php 
            echo format_value($_1);
            ?>
</th></tr><tr><td><?php 
            echo format_word(PATH($w, $_1)->get(), $w->lang(), true);
            ?>
</td></tr><?php 
        }
    } else {
        ?>
<table class="text-left inflection" id="word<?php 
        echo $w->id();
        ?>
_forms"><?php 
        $first0 = $last0 = NULL;
        _get_first_last($values0, $first0, $last0);
        if (!$values0) {
            $values0 = [FALSE];
            $values1 = [$values1, "_" => $values1];
            $values2 = [$values2, "_" => $values2];
            $values3 = [$values3, "_" => $values3];
            $values4 = [$values4, "_" => $values4];
        }
        foreach ($values0 as $_key => $_0) {
            $name0 = $_0;
            // FIXME
            if ($name0 === " ") {
                $name0 = FALSE;
            }
            if (!$values1[$_0]) {
                $values1[$_0] = [FALSE];
            }
            if (!$values2[$_0]) {
                $values2[$_0] = [FALSE];
            }
            if (!$values3[$_0]) {
                $values3[$_0] = [FALSE];
            }
            if (!$values4[$_0]) {
                $values4[$_0] = [FALSE];
            }
            $path = PATH($w, $_0);
            if ($_0 !== $first0) {
                // Blank row to separate sub-tables based on $values0
                ?>
<tr><th>&nbsp;</th></tr><?php 
            }
            // values0 : table name
            // values1 : major vertical
            // values2 : minor vertical
            // values3 : major horizontal
            // values4 : minor horizontal
            $_1 = (count($values1[$_0]) > 1 or $values1[$_0][0] !== FALSE);
            ?>
<tr><?php 
            $hspan1 = $_1 !== FALSE ? 2 : 1;
            if ($name0 === FALSE) {
                ?>
<th colspan="<?php 
                echo $hspan1;
                ?>
">&nbsp;</th><?php 
            } else {
                ?>
<th colspan="<?php 
                echo $hspan1;
                ?>
" class="greatest"><?php 
                echo $format_value($name0);
                ?>
</th><?php 
            }
            if ($values3[$_0]) {
                foreach ($values3[$_0] as $_3) {
                    ?>
<th colspan="<?php 
                    echo count($values4[$_0][$_3]);
                    ?>
" class="major"><?php 
                    echo $format_value($_3);
                    ?>
</th><?php 
                }
            }
            ?>
</tr><?php 
            if (!array_key_exists("_", $values4[$_0])) {
                $values4[$_0]["_"] = [];
            }
            if ($values4[$_0]["_"] and $values4[$_0]["_"][0] !== FALSE) {
                ?>
<tr><th colspan="<?php 
                echo $hspan1;
                ?>
">&nbsp;</th><?php 
                foreach ($values3[$_0] as $_3) {
                    if ($values4[$_0][$_3]) {
                        foreach ($values4[$_0][$_3] as $_4) {
                            ?>
<th class="minor"><?php 
                            echo $format_value($_4);
                            ?>
</th><?php 
                        }
                    }
                }
                ?>
</tr><?php 
                $hspan4 = 1;
            } elseif ($values4[$_0]["_"]) {
                $hspan4 = count($values4[$_0]["_"]);
                foreach ($values4[$_0] as &$v) {
                    $v = [""];
                }
            } else {
                $hspan4 = 1;
            }
            foreach ($values1[$_0] as $_1) {
                if ($_1 !== FALSE) {
                    ?>
<tr><?php 
                    ?>
<th colspan="2" class="major"><?php 
                    echo $format_value($_1);
                    ?>
</th><?php 
                    ?>
</tr><?php 
                }
                // Previous row (directly above)
                $p_2 = NULL;
                foreach ($values2[$_0][$_1] as $_2) {
                    ?>
<tr><?php 
                    if ($_1 !== FALSE) {
                        ?>
<th>&nbsp;&nbsp;&nbsp;</th><?php 
                    }
                    ?>
<th class="minor"><?php 
                    echo $format_value($_2);
                    ?>
</th><?php 
                    $row = [];
                    $last = NULL;
                    foreach ($values3[$_0] as $_3) {
                        $acc = [];
                        $i = -1;
                        foreach ($values4[$_0][$_3] as $_4) {
                            $p = PATH($w, $_0, $_1, $_3, $_4, $_2);
                            if ($i < 0 or $p->get() != $last or !$last) {
                                $acc[] = [];
                                $last = $p->get();
                                $i += 1;
                            }
                            $acc[$i][] = [$p, 2 => $_3, $_4];
                        }
                        if (!($optimization & 2) or count($acc) != 1 and count($acc) != count($values4)) {
                            $acc = [];
                            foreach ($values4[$_0][$_3] as $_4) {
                                $p = PATH($w, $_0, $_1, $_3, $_4, $_2);
                                $acc[] = [[$p, 2 => $_3, $_4]];
                            }
                        }
                        $row = array_merge($row, $acc);
                    }
                    $first1 = $last1 = NULL;
                    _get_first_last($values1[$_0], $first1, $last1);
                    $first2 = $last2 = NULL;
                    _get_first_last($values2[$_0][$_1], $first2, $last2);
                    $first3 = $last3 = NULL;
                    _get_first_last($values3[$_0], $first3, $last3);
                    $first4 = $last4 = NULL;
                    _get_first_last($values4[$_0][$_3], $first4, $last4);
                    foreach ($row as $val_group) {
                        $p = $val_group[0][0];
                        $_ = count($val_group) - 1;
                        $_30 = $val_group[0][2];
                        $_40 = $val_group[0][3];
                        $_31 = $val_group[$_][2];
                        $_41 = $val_group[$_][3];
                        if ($_ === 0) {
                            $_3 = $_30;
                            $_4 = $_40;
                            $ditto = ($p_2 and $p->get() and PATH($w, $_0, $_1, $_3, $_4, $p_2)->get() == $p->get());
                        } else {
                            $_3 = $_4 = NULL;
                            $ditto = FALSE;
                        }
                        ?>
<td colspan="<?php 
                        echo $hspan4 * count($val_group);
                        ?>
" <?php 
                        $classes = "";
                        if (!$first4 or $_40 === $first4) {
                            $classes .= " leftline";
                        }
                        if (!$last4 or $_41 === $last4) {
                            $classes .= " rightline";
                        }
                        if (!$first2 or $_2 === $first2) {
                            $classes .= " topline";
                        }
                        if (!$last2 or $_2 === $last2) {
                            $classes .= " bottomline";
                        }
                        if ((!$first4 or $_40 === $first4) and $_30 !== $first3) {
                            $classes .= " leftline";
                        }
                        echo " class='{$classes}' ";
                        if (count($val_group) > 1) {
                            echo " style='text-align: center;'";
                        }
                        ?>
><?php 
                        if ($get_link !== NULL) {
                            $link = $get_link($p);
                        } else {
                            $link = NULL;
                        }
                        if (ISWORD($link)) {
                            $link = "dictionary.php?id=" . $link->id();
                        }
                        if ($link) {
                            ?>
<a class="word-ref" href="<?php 
                            echo $link;
                            ?>
"><?php 
                        }
                        if (!_in_ignore($p, $ignore) or !$p->hasvalue()) {
                            $val = $format_word($p->get(), $p);
                        } else {
                            $val = '<abbr class="symbolic" title="You\'ve not learned this yet">—</abbr>';
                        }
                        if (count($val_group) > 1) {
                            $val = "" . "<span style='float: right;'>→</span>" . "<span style='float: left;'>←</span>" . $val;
                        } elseif ($ditto and $optimization & 1) {
                            $val = "&nbsp;&nbsp;&nbsp;&nbsp;&#8243;";
                            # ditto mark
                            $val = "&nbsp;&#x2044;&nbsp;&#x2044;";
                            #echo "↓";
                        }
                        echo $val;
                        if ($link) {
                            ?>
</a><?php 
                        }
                        if ($extras !== NULL) {
                            $extras($p);
                        }
                        ?>
</td><?php 
                    }
                    ?>
</tr><?php 
                    $p_2 = $_2;
                }
            }
        }
    }
    ?>
</table></div><?php 
}
Пример #5
0
 /**
  * Get the formatted value of a field
  *
  * This is used for HTML and non-HTML output so HTML should not be added
  * - see printFieldValue below for that.
  */
 public function getFormattedValue($name, $value = null)
 {
     if (!isset($this->fields[$name])) {
         trigger_error('Cannot get value for field ' . ents($name) . ' - field does not exist', E_USER_WARNING);
         return NULL;
     }
     if (is_null($value)) {
         $value = array_get($this->values, $name, NULL);
     }
     $field = $this->fields[$name];
     return format_value($value, $field);
 }
Пример #6
0
 /**
  * Add a block of text to the top of the specified note showing the values supplied for this template's fields
  * Used when saving a note.
  * @param Person_Note $note	The note object to append text to.
  */
 public function applyDataBlock($note)
 {
     $res = '';
     $fields = $GLOBALS['system']->getDBObjectData('note_template_field', array('templateid' => $this->id), 'OR', 'rank');
     $maxLength = 0;
     foreach ($fields as $id => $details) {
         $params = unserialize($details['params']);
         $params['type'] = $details['type'];
         $line = ($details['customfieldid'] ? $details['customfieldname'] : $details['label']) . ': ';
         if ($details['customfieldid']) {
             $cf = $GLOBALS['system']->getDBObject('custom_field', $details['customfieldid']);
             $line .= $cf->formatValue($this->_field_values[$id]);
         } else {
             $line .= format_value($this->_field_values[$id], $params);
         }
         $maxLength = max($maxLength, strlen($line));
         $res .= $line . "\n";
     }
     $divider = str_repeat('-', (int) ($maxLength * 1.6));
     $res = $res . $divider . "\n";
     $note->setValue('details', $res . $note->getValue('details'));
 }
Пример #7
0
-<?php 
                    echo $k;
                    ?>
"
								   id="word<?php 
                    echo $id;
                    ?>
-div-<?php 
                    echo $v;
                    ?>
"
								   value="<?php 
                    echo $v;
                    ?>
" ><?php 
                    echo format_value($v);
                    ?>
</label></div><?php 
                }
                ?>
</span><?php 
            }
            ?>
 <span class="select">
					<div>
					<input id="word<?php 
            echo $id;
            ?>
_value" type="text" placeholder="form, ..." required>
					<button id="word<?php 
            echo $id;
Пример #8
0
function humanize_sensor(&$sensor)
{
    // Exit if already humanized
    if ($sensor['humanized']) {
        return;
    }
    $sensor['sensor_symbol'] = $GLOBALS['config']['sensor_types'][$sensor['sensor_class']]['symbol'];
    $sensor['sensor_format'] = strval($GLOBALS['config']['sensor_types'][$sensor['sensor_class']]['format']);
    $sensor['state_class'] = '';
    //'text-success';
    // Generate "pretty" thresholds
    if (is_numeric($sensor['sensor_limit_low'])) {
        $sensor_threshold_low = format_value($sensor['sensor_limit_low'], $sensor['sensor_format']) . $sensor['sensor_symbol'];
    } else {
        $sensor_threshold_low = "&infin;";
    }
    if (is_numeric($sensor['sensor_limit_low_warn'])) {
        $sensor_warn_low = format_value($sensor['sensor_limit_low_warn'], $sensor['sensor_format']) . $sensor['sensor_symbol'];
    } else {
        $sensor_warn_low = NULL;
    }
    if ($sensor_warn_low) {
        $sensor_threshold_low = $sensor_threshold_low . " (" . $sensor_warn_low . ")";
    }
    if (is_numeric($sensor['sensor_limit'])) {
        $sensor_threshold_high = format_value($sensor['sensor_limit'], $sensor['sensor_format']) . $sensor['sensor_symbol'];
    } else {
        $sensor_threshold_high = "&infin;";
    }
    if (is_numeric($sensor['sensor_limit_warn'])) {
        $sensor_warn_high = format_value($sensor['sensor_limit_warn'], $sensor['sensor_format']) . $sensor['sensor_symbol'];
    } else {
        $sensor_wanr_high = "&infin;";
    }
    if ($sensor_warn_high) {
        $sensor_threshold_high = "(" . $sensor_warn_high . ") " . $sensor_threshold_high;
    }
    $sensor['sensor_thresholds'] = $sensor_threshold_low . ' - ' . $sensor_threshold_high;
    // generate pretty value
    if (!is_numeric($sensor['sensor_value'])) {
        $sensor['human_value'] = 'NaN';
        $sensor['sensor_symbol'] = '';
    } else {
        $sensor['human_value'] = format_value($sensor['sensor_value'], $sensor['sensor_format']);
    }
    switch ($sensor['sensor_event']) {
        case 'up':
        case 'ok':
            $sensor['state_class'] = 'label label-success';
            $sensor['row_class'] = 'up';
            break;
        case 'warning':
            $sensor['state_class'] = 'label label-warning';
            $sensor['row_class'] = 'warning';
            break;
        case 'alert':
            $sensor['state_class'] = 'label label-important';
            $sensor['row_class'] = 'error';
            break;
        case 'ignore':
            $sensor['state_class'] = 'label';
            $sensor['row_class'] = 'ignored';
            break;
        default:
            $sensor['state_class'] = 'label label-primary';
            // $sensor['row_class']   = NULL;
    }
    $device =& $GLOBALS['cache']['devices']['id'][$sensor['device_id']];
    if (isset($device['status']) && !$device['status'] || isset($device['disabled']) && $device['disabled']) {
        $sensor['row_class'] = 'error';
    }
    // Set humanized entry in the array so we can tell later
    $sensor['humanized'] = TRUE;
}
Пример #9
0
</div>

<div class="section">
<h2>Mails Sent</h2>
<?php 
while ($mail = $sentMails->next()) {
    ?>
  <div class="email">
    <h3 class="subject"><?php 
    echo htmlspecialchars($mail->subject);
    ?>
</h3>
    <div class="date">
      Sent
      <?php 
    echo format_value(format_datetime_ago($mail->sent));
    ?>
      (<?php 
    echo $mail->sent;
    ?>
)
    </div>
    <blockquote>
      <?php 
    echo htmlspecialchars($mail->plaintext);
    ?>
    </blockquote>
  </div>
<?php 
}
?>
Пример #10
0
    if ($note->adminid == $admin_id) {
        ?>

    <div style="float: right"><a class="deletenote" href="<?php 
        echo site_url("admin/volunteers/deletenote/{$user->id}/{$note->id}");
        ?>
"
                                 onclick="return confirm('This note will be permanently deleted. Are you sure?');">Delete</a>
    </div>
  <?php 
    }
    ?>
   </div>
  <div class="content">
  <?php 
    echo format_value($note->content);
    ?>
   </div>
</div>
<?php 
}
?>

<div id="addnote">
  <?php 
echo form_open('admin/volunteers/addnote');
?>
    <input type="hidden" name="userid" value="<?php 
echo $user->id;
?>
"/>
Пример #11
0
<div class="fields">
<?php 
    foreach ($section->fields as $field) {
        ?>
  <?php 
        foreach ($field as $id => $label) {
            ?>
    <div class="field">
      <div class="name">
        <?php 
            echo htmlspecialchars($label);
            ?>
      </div>
      <div class="value">
        <?php 
            echo format_value($data[$id]);
            ?>
      </div>
    </div>
  <?php 
        }
    }
    ?>
</div>
<?php 
}
?>
</div>

<?php 
vt_footer();