Example #1
0
 /**
  * calculateTagSize
  * modified the script so only one table is now used to calculate the tag size.
  * Add a time parameter so more recently clicked tag have more weigth than older clicks.
  * 
  */
 function calculateTagSize($do_User = NULL)
 {
     $max_font = 40;
     $min_font = 12;
     $tag_weight = 20;
     $reference_type = $this->default_reference;
     $this->setLog("\n Calculating tag sizes at " . date("Y/m/d H:i:s") . " last_calculate:" . $_SESSION['last_tag_refresh']);
     if ($do_User == NULL) {
         $do_User = $_SESSION['do_User'];
     }
     $q_clicks = new DataObject();
     $q_clicks->setTable("tag_click");
     $q_clicks->query("SELECT tag_name, clicked FROM  tag_click WHERE tag_click.iduser="******" ORDER BY clicked DESC");
     $this->setLog("\n Tag click list:" . $q_clicks->getSqlQuery());
     $num_tag_clicked = 0;
     $max_weight = 0;
     while ($q_clicks->next()) {
         $ar_tags_weight[$q_clicks->tag_name] += $tag_weight;
         if ($ar_tags_weight[$q_clicks->tag_name] > $max_weight) {
             $max_weight = $ar_tags_weight[$q_clicks->tag_name];
         }
         $this->setLog("\n " . $q_clicks->tag_name . " at " . $q_clicks->clicked . " weight:" . $tag_weight . " tag weight:" . $ar_tags_weight[$q_clicks->tag_name]);
     }
     if ($q_clicks->getNumRows() == 0) {
         $q_size = new sqlQuery($this->getDbCon());
         $q_size->query("DELETE FROM tag_size WHERE iduser="******"SELECT tag_name FROM tag WHERE reference_type='" . $reference_type . "' AND iduser="******" GROUP BY tag_name");
         while ($this->next()) {
             $q_size->query("INSERT INTO tag_size (tag_name, clicks, iduser) VALUES ('" . $this->tag_name . "', 16, " . $do_User->iduser . ")");
         }
         $q_size->free();
     }
     if ($max_weight > 0) {
         $q_size = new sqlQuery($this->getDbCon());
         $q_size->query("DELETE FROM tag_size WHERE iduser="******"\n Tag " . $tag_name . " size: " . $ar_tag_size[$tag_name] . " = " . $final_weight . "*(" . $max_font . "/" . $max_weight . ") = " . $max_font / ($max_weight + 1) . " -");
         }
         $q_tags = new sqlQuery($this->getDbCon());
         $this->query("SELECT tag_name FROM tag WHERE reference_type='" . $reference_type . "' AND iduser="******" GROUP BY tag_name");
         while ($this->next()) {
             if (isset($ar_tag_size[$this->tag_name])) {
                 $tag_size = $ar_tag_size[$this->tag_name];
             } else {
                 $tag_size = $min_font;
             }
             $q_size->query("INSERT INTO tag_size (tag_name, clicks, iduser) VALUES ('" . $this->tag_name . "', " . $tag_size . ", " . $do_User->iduser . ")");
         }
         $q_size->free();
     }
     $q_clicks->query("DELETE FROM tag_click WHERE iduser="******" AND clicked < date_sub(now(), interval 1 month)");
     $q_clicks->free();
 }
{
    list($month, $day, $year) = explode("/", $sheet_date);
    return "20" . $year . "-" . $month . "-" . $day;
}
function money2float($money_string)
{
    $money_float = str_replace("\$", "", $money_string);
    $money_float = str_replace(",", "", $money_float);
    return $money_float;
}
if (file_exists($import_file)) {
    $fp = fopen($import_file, "r");
    $i = 0;
    $total = 0;
    while ($fields = fgetcsv($fp)) {
        $i++;
        $do_expense_import->newRecord();
        $do_expense_import->category = $fields[0];
        $do_expense_import->debit_date = format_sql_date($fields[1]);
        $do_expense_import->description = $fields[3];
        $do_expense_import->payment_method = $fields[4];
        $do_expense_import->amount = money2float($fields[5]);
        $do_expense_import->add();
        $total += money2float($fields[5]);
        $this->setLog("\n insert with: " . $do_expense_import->getSqlQuery());
    }
}
$this->setLog("\n imported a total of: " . $total);
$disp = new Display($goto);
$disp->addParam("message", "Import completed");
$this->setDisplayNext($disp);