Beispiel #1
0
function user_register($userName, $userPassword, $checkbox)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully</br>";
    }
    $sql = <<<EOF
    SELECT * FROM User WHERE name = '{$userName}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            header("Location: http://www.kmoving.com/user/register.php?Error=userExist");
        } else {
            $sql = <<<EOF
            INSERT INTO User (name, password, last, doctor, gender, height, weight, country, city, address)
            VALUES ('{$userName}', '{$userPassword}', '{$userName}', '{$checkbox}', '--', '--', '--', '--', '--', '--');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
                $db->close();
                setcookie("username", $userName, null, "/");
                header("Location: http://www.kmoving.com/server/user/user_details.php");
            }
        }
    }
    $db->close();
}
function add_member($activityId)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userId = get_userId();
    $sql = <<<EOF
    SELECT * FROM ActivityMember WHERE userId={$userId} and activityId={$activityId};
EOF;
    $ret = $db->query($sql);
    if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
        $db->close();
        header("Location: http://www.kmoving.com/user/groups/activity.php?msg=memberExist");
    } else {
        $data = $_COOKIE['date'];
        $sql = <<<EOF
            INSERT INTO ActivityMember (userId, activityId, createAt)
            VALUES ('{$userId}', '{$activityId}', '{$data}');
EOF;
        $ret = $db->exec($sql);
        if (!$ret) {
            echo $db->lastErrorMsg();
        } else {
            $db->close();
            header("Location: http://www.kmoving.com/user/groups/activity.php");
        }
    }
}
Beispiel #3
0
function activity_delete($delete_ID)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $sql = <<<EOF
      DELETE from Activity where id = {$delete_ID};
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        $sql = <<<EOF
        DELETE from ActivityMember where activityId = {$delete_ID};
EOF;
        $ret = $db->exec($sql);
        if (!$ret) {
            echo $db->lastErrorMsg();
        } else {
            $db->close();
            header("Location: http://www.kmoving.com/user/groups/activity.php");
        }
    }
}
Beispiel #4
0
function go_digital_panel()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully</br>";
    }
    $userName = $_COOKIE["username"];
    $sql = <<<EOF
    SELECT * FROM User WHERE name = '{$userName}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $name = $row["name"];
            $gender = $row["gender"];
            $height = $row["height"];
            $weight = $row["weight"];
            $date = date("Y-m-d");
            setcookie("date", $date, null, "/");
            $url = "http://www.kmoving.com/home.php?name={$name}&gender={$gender}&height={$height}&weight={$weight}";
            header("Location: {$url}");
        }
    }
    $db->close();
}
function csvToJson($filename, $separator = ",")
{
    //create the resulting array
    $result = array("records" => array());
    //check if the file handle is valid
    //echo $filename;
    if (($handle = fopen($filename, "r")) !== false) {
        //"Contact","Company","Business Email","Business Phone","Direct Phone","Time Zone","Fax","Web","Source"
        //check if the provided file has the right format
        if (($data = fgetcsv($handle, 4096, $separator)) == false || ($data[0] != "Contact" || $data[1] != "Company" || $data[2] != "Business Email")) {
            throw new InvalidImportFileFormatException(sprintf('The provided file (%s) has the wrong format!', $filename));
        }
        $db = new MyDB();
        if (!$db) {
            echo $db->lastErrorMsg();
        } else {
            echo "Opened database successfully\n";
        }
        //loop through your data
        while (($data = fgetcsv($handle, 4096, $separator)) !== false) {
            $TZ = $db->UpdateTimeZone($data[3]);
            echo json_encode($TZ);
            //store each line in the resulting array
            $result['records'][] = array("Contact" => $data[0], "Business Email" => $data[2], "Business Phone" => $data[3], "Time Zone" => $TZ);
        }
        //close the filehandle
        $db->close();
        fclose($handle);
    }
    //return the json encoded result
    //echo json_encode($result);
    return;
}
Beispiel #6
0
function get_user_len()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $sql = <<<EOF
    SELECT count(*) AS length FROM User;
EOF;
    $ret = $db->query($sql);
    if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
        $db->close();
        return $row['length'];
    }
    $db->close();
    return null;
}
Beispiel #7
0
function import_advice($address)
{
    $reader = PHPExcel_IOFactory::createReader('Excel5');
    $PHPExcel = $reader->load($address);
    // 载入excel文件
    $sheet = $PHPExcel->getSheet(0);
    // 读取第一個工作表
    $highestRow = $sheet->getHighestRow();
    // 取得总行数
    $highestColumm = $sheet->getHighestColumn();
    // 取得总列数
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $title = "";
    $content = "";
    $toUserId = 0;
    $authorId = 0;
    for ($row = 1; $row <= $highestRow; $row++) {
        //行数是以第1行开始
        for ($column = 'A'; $column <= $highestColumm; $column++) {
            //列数是以A列开始
            if ($row != 1) {
                switch ($column) {
                    case 'A':
                        $title = $sheet->getCell($column . $row)->getValue();
                        break;
                    case 'B':
                        $content = $sheet->getCell($column . $row)->getValue();
                        break;
                    case 'C':
                        $toUserId = $sheet->getCell($column . $row)->getValue();
                        break;
                    case 'D':
                        $authorId = $sheet->getCell($column . $row)->getValue();
                        break;
                }
            }
        }
        if ($row != 1) {
            $sql = <<<EOF
            INSERT INTO Advice (title, content, toUserId, authorId)
            VALUES ('{$title}', '{$content}', '{$toUserId}', '{$authorId}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
    header("Location: http://www.kmoving.com/user/advice.php");
}
Beispiel #8
0
function advice_create($title, $content, $toUserId, $authorId)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully</br>";
    }
    $sql = <<<EOF
            INSERT INTO Advice (title, content, toUserId, authorId)
            VALUES ('{$title}', '{$content}', '{$toUserId}', '{$authorId}');
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        $db->close();
        header("Location: http://www.kmoving.com/user/advice_create.php?msg=success");
    }
    $db->close();
}
Beispiel #9
0
function create_activity($title, $target, $content, $authorId)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully</br>";
    }
    $sql = <<<EOF
            INSERT INTO Activity (title, target, content, authorId)
            VALUES ('{$title}', '{$target}', '{$content}', '{$authorId}');
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        $db->close();
        header("Location: http://www.kmoving.com/user/groups/activity.php");
    }
    $db->close();
}
Beispiel #10
0
function activity_refresh($id, $title, $target, $content)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $sql = <<<EOF
      UPDATE Activity SET title='{$title}',target='{$target}',content='{$content}' where id={$id};
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    }
    $db->close();
}
Beispiel #11
0
function set_user_settings($gender, $height, $weight, $birth, $country, $city, $address)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully</br>";
    }
    $userName = $_COOKIE["username"];
    $sql = <<<EOF
      UPDATE User set gender='{$gender}', height='{$height}', weight='{$weight}', birth='{$birth}',country='{$country}',city='{$city}',address='{$address}' where name='{$userName}';
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        header("Location: http://www.kmoving.com/server/user/settings.php");
    }
    $db->close();
}
Beispiel #12
0
function addToDB($ip, $time, $session, $message)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
        echo "Opened database successfully\n";
    }
    $sql = <<<EOF
   INSERT INTO test (ip,time,session,message)
   VALUES('{$ip}', '{$time}', '{$session}', '{$message}');

EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        echo "Records created successfully\n";
    }
    $db->close();
}
 function GetSearchCardName($message)
 {
     $attribute = array("0" => "", "1" => "Earth", "2" => "Water", "4" => "Fire", "8" => "Wind", "16" => "Light", "32" => "Dark", "64" => "Divine");
     $race = array("1" => "Warrior", "2" => "Spellcaster", "4" => "Fairy", "16" => "Zombie", "8" => "Unterweltler", "32" => "Maschine", "64" => "Aqua", "128" => "Pyro", "256" => "Rock", "512" => "Winged Beast", "1024" => "Plant", "2048" => "Insect", "4096" => "Thunder", "8192" => "Dragon", "16384" => "Beast", "32768" => "Beast-Warrior", "65536" => "Dinosaur", "131072" => "Fish", "262144" => "Sea Searpent", "524288" => "Reptile", "1048576" => "Psychic", "2097152" => "flying Beast");
     $message = substr($message, 1);
     $db = new MyDB();
     $abfrage = "\n                  SELECT\n                    texts.id, name, desc, datas.type, datas.attribute, datas.race, datas.level, datas.atk, datas.def\n                  FROM\n                    texts\n                  LEFT JOIN\n                    datas\n                  ON\n                    texts.id = datas.id\n                  WHERE\n                    texts.name LIKE '%{$message}%'\n                  LIMIT\n                    1\n                ";
     $ergebnis = $db->query($abfrage) or die("Error in query: <span style='color:red;'>{$abfrage}</span>");
     // Counter fuer array setzen
     $result = '';
     while ($row = $ergebnis->fetchArray()) {
         //$result .= $row['id'];
         //$result  .= utf8_decode($row['name']);
         $result .= 'attr: ' . $attribute[$row['attribute']] . '  |  ';
         $result .= 'race: ' . $race[$row['race']] . '  |  ';
         $result .= 'level: ' . $row['level'] . '  |  ';
         $result .= 'atk' . $row['atk'] . '  |  ';
         $result .= 'def: ' . $row['def'];
     }
     $db->close();
     // $res = implode($result);
     return $result;
 }
Beispiel #14
0
function convert()
{
    global $tmp_path, $db_filename, $inpx_input;
    $db = new MyDB($tmp_path . $db_filename);
    if (!$db) {
        die($db->lastErrorMsg());
    }
    $db->create();
    // get the absolute path to $file
    //$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
    $zip = new ZipArchive();
    $res = $zip->open($inpx_input);
    if ($res === TRUE) {
        // extract it to the path we determined above
        $zip->extractTo($tmp_path);
        $zip->close();
        echo "{$file} extracted to {$tmp_path}\n";
    } else {
        echo "Doh! I couldn't open {$inpx_input}\n";
    }
    $sep = chr(0x4);
    foreach (glob($tmp_path . '*.inp') as $file) {
        echo $file . "\n";
        $records = explode("\n", file_get_contents($file));
        foreach ($records as $rec) {
            $array = explode($sep, $rec);
            $authors_ids = array();
            $authors = explode(':', $array[0]);
            foreach ($authors as $author) {
                if (!empty($author)) {
                    $author = trim(str_replace(',', ' ', $author), " -\t\r!@#\$%^&*()_=+|");
                    $author_id = $db->addAuthor($author);
                    //echo "$author_id -> $author\n";
                    if ($author_id) {
                        $authors_ids[] = $author_id;
                    }
                }
            }
            $genres_ids = array();
            $genres = explode(':', $array[1]);
            foreach ($genres as $genre) {
                if (!empty($genre)) {
                    $genre_id = $db->addGenre($genre);
                    //echo "$genre_id -> $genre\n";
                    if ($genre_id) {
                        $genres_ids[] = $genre_id;
                    }
                }
            }
            $title = trim($array[2], " \t");
            $title_id = $db->addTitle($title);
            //echo "$title_id -> $title\n";
            $file_name = trim($array[5], " \t");
            $file_size = trim($array[6], " \t");
            $file_ext = trim($array[9], " \t");
            $date_add = trim($array[10], " \t");
            $lang = trim($array[11], "' \t");
            //echo "$file_name $file_ext\n";
            $db->addFile($authors_ids, $genres_ids, $title_id, $file_name, $file_ext, $file_size, $lang, $date_add);
        }
    }
    $db->close();
    rename($tmp_path . $db_filename, './' . $db_filename);
    // TODO: cleanup temporary directory
    exit;
}
Beispiel #15
0
function update_workouts($title, $steps, $km, $calories, $time)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $date = $_COOKIE['date'];
    $sql = <<<EOF
    SELECT * FROM User,Workouts WHERE User.name='{$userName}' and User.id=Workouts.userId and Workouts.createAt='{$date}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $userId = $row['userId'];
            $sql = <<<EOF
            UPDATE Workouts SET title='{$title}',steps='{$steps}',
            distance='{$km}',calories='{$calories}',time='{$time}'
            where userId={$userId} and createAt={$date};
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        } else {
            $userId = get_userId($userName);
            $sql = <<<EOF
            INSERT INTO Workouts (userId, title, steps, distance, calories, time, createAt)
            VALUES ('{$userId}', '{$title}', '{$steps}', '{$km}', '{$calories}', '{$time}', '{$date}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
}
    public function getTimeZoneForARecord($arg)
    {
        $db = new MyDB();
        if (!$db) {
            echo $db->lastErrorMsg();
        } else {
            echo "Opened database successfully\n";
        }
        $sql = <<<EOF
      select tz.timezonecode from statearea sa, state st, timezone tz where sa.stateid = st.stateid and sa.areacode = {$arg} and tz.tzid = st.defaulttzid;
EOF;
        $ret = $db->query($sql);
        while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            echo json_encode($row);
        }
        echo "Operation done successfully\n";
        $db->close();
        echo json_encode(array('contacts' => array('contact' => array('phonenumber' => 9884056307.0, 'name' => 'Radhika'))));
    }
Beispiel #17
0
 function getHistory()
 {
     $db = new MyDB();
     // $db->connect();
     $results = $db->getHistory($this->id);
     $db->close();
     if ($results == false) {
         echo "History is empty";
     } else {
         echo '<table border="1" style="width:100%">';
         echo '<tr> <th>Filename</th> <th>Upload Time</th> <th>Message</th> </tr>';
         while ($row = $results->fetch_assoc()) {
             $filename = $row['file'];
             $date = $row['date'];
             $msg = $row['message'];
             echo "<tr> <td>{$filename}</td> <td>{$date}</td> <td>{$msg}</td> </tr>";
         }
         echo '</table>';
     }
 }
Beispiel #18
0
function loadCurrent()
{
    $db = new MyDB("sqltemptime.db");
    if (!$db) {
        echo $db->lastErrorMsg();
    }
    $logArray = [];
    $sql = <<<EOF
\t\tSELECT * FROM schema WHERE id = (SELECT MAX(id) FROM schema);
EOF;
    $ret = $db->query($sql);
    $row = $ret->fetchArray();
    for ($i = 0; $i < 6; $i++) {
        array_push($logArray, $row[$i]);
    }
    $id = $logArray[0];
    $dataArray = [];
    $sql = <<<EOF
\t\tSELECT time, temp FROM timeTemp WHERE id = "{$id}";
EOF;
    $ret = $db->query($sql);
    while ($row = $ret->fetchArray()) {
        array_push($dataArray, [$row[0], $row[1]]);
    }
    echo json_encode([$logArray, $dataArray]);
    $db->close();
}
Beispiel #19
0
<?php

include "database/MyDB.php";
if (!isset($_POST['submit'])) {
    exit('非法访问!');
}
$id = $_POST['del_id'];
//auth access info
$appauthname = $_POST['appauthname'];
$appauthpwd = $_POST['appauthpwd'];
if ($appauthname != "yarlung") {
    die("授权帐号出错! <br/>");
}
if ($appauthpwd != "yarlung01") {
    die("授权密码不正确! <br/>");
}
if (empty($id)) {
    die("没有选中要删除的应用!<br/>");
}
$dblink = new MyDB();
foreach ($id as $ide) {
    echo "删除UID为 " . $ide . " 的应用!<br/>";
    $qry = "DELETE FROM appinfo WHERE uid ={$ide}";
    $dblink->query($qry);
}
$dblink->close();
}
$booksdb->close();
if (count($books) == 0) {
    die("No books found in your library. Have you added any to iBooks?\n");
}
// Retrieve the notes.
$notesdb = new MyDB(NOTES_DATABASE_FILE);
if (!$notesdb) {
    echo $notesdb->lastErrorMsg();
}
$notes = array();
$res = $notesdb->query("\n\t\t\tSELECT\n\t\t\t\tZANNOTATIONREPRESENTATIVETEXT as BroaderText,\n\t\t\t\tZANNOTATIONSELECTEDTEXT as SelectedText,\n\t\t\t\tZANNOTATIONNOTE as Note,\n\t\t\t\tZFUTUREPROOFING5 as Chapter,\n\t\t\t\tZANNOTATIONCREATIONDATE as Created,\n\t\t\t\tZANNOTATIONMODIFICATIONDATE as Modified,\n\t\t\t\tZANNOTATIONASSETID\n\t\t\tFROM ZAEANNOTATION\n\t\t\tWHERE ZANNOTATIONSELECTEDTEXT IS NOT NULL\n\t\t\tORDER BY ZANNOTATIONASSETID ASC,Created ASC");
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
    $notes[$row['ZANNOTATIONASSETID']][] = $row;
}
$notesdb->close();
if (count($notes) == 0) {
    die("No notes found in your library. Have you added any to iBooks?\n\nIf you did on other devices than this Mac, make sure to enable iBooks notes/bookmarks syncing on all devices.");
}
// Create a new directory and cd into it
mkdir(RESULT_DIRECTORY_NAME);
chdir(RESULT_DIRECTORY_NAME);
$i = 0;
$j = 0;
$b = 0;
foreach ($notes as $AssetID => $booknotes) {
    $Body = '<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export3.dtd">
	<en-export export-date="' . @strftime('%Y%m%dT%H%M%S', time()) . '" application="iBooks2Evernote" version="iBooks2Evernote Mac 0.0.1">';
    $BookTitle = $books[$AssetID]['Title'];
    $j = 0;
Beispiel #21
0
function update_mood($mood_image)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $date = $_COOKIE['date'];
    $sql = <<<EOF
    SELECT * FROM User,Mood WHERE User.name='{$userName}' and User.id=Mood.userId and Mood.createAt='{$date}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $userId = $row['userId'];
            $sql = <<<EOF
            UPDATE Mood
            SET mood='{$mood_image}'
            where userId={$userId} and createAt={$date};
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        } else {
            $userId = get_userId($userName);
            $sql = <<<EOF
            INSERT INTO Mood (userId, mood, createAt)
            VALUES ('{$userId}', '{$mood_image}', '{$date}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
}
Beispiel #22
0
function update_moves($active_time, $inactive_time, $calories, $wo_calories, $bg_calories, $bmr_day, $steps, $km)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $date = $_COOKIE['date'];
    $sql = <<<EOF
    SELECT * FROM User,Moves WHERE User.name='{$userName}' and User.id=Moves.userId and Moves.createAt='{$date}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $userId = $row['userId'];
            $sql = <<<EOF
            UPDATE Moves
            SET active='{$active_time}',free='{$inactive_time}',
            total_calories='{$calories}',workouts_calories='{$wo_calories}',
            static_calories='{$bg_calories}',daixie='{$bmr_day}',steps='{$steps}',distance='{$km}'
            where userId={$userId} and createAt={$date};
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        } else {
            $userId = get_userId($userName);
            $sql = <<<EOF
            INSERT INTO Moves (userId, active, free, total_calories, workouts_calories, static_calories, daixie, steps, distance, createAt)
            VALUES ('{$userId}', '{$active_time}', '{$inactive_time}', '{$calories}', '{$wo_calories}', '{$bg_calories}', '{$bmr_day}', '{$steps}', '{$km}' , '{$date}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
}
Beispiel #23
0
function update_meals($title, $calories, $fat, $protein, $calcium, $carbohydrate, $sugar, $cholesterol, $vitamin_c, $vitamin_a)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $date = $_COOKIE['date'];
    $sql = <<<EOF
    SELECT * FROM User,Meals WHERE User.name='{$userName}' and User.id=Meals.userId and Meals.createAt='{$date}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $userId = $row['userId'];
            $sql = <<<EOF
            UPDATE Meals
            SET title='{$title}',calories='{$calories}',fat='{$fat}',
            protein='{$protein}',calcium='{$calcium}',carbohydrate='{$carbohydrate}',
            vitamin_c='{$vitamin_c}',vitamin_a='{$vitamin_a}'
            where userId={$userId} and createAt={$date};
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        } else {
            $userId = get_userId($userName);
            $sql = <<<EOF
            INSERT INTO Meals (userId, title, calories, fat, protein, calcium, carbohydrate, sugar, cholesterol, vitamin_c, vitamin_a, createAt)
            VALUES ('{$userId}', '{$title}', '{$calories}', '{$fat}', '{$protein}', '{$calcium}', '{$carbohydrate}', '{$sugar}', '{$cholesterol}', '{$vitamin_c}', '{$vitamin_a}', '{$date}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
}
Beispiel #24
0
function get_comments()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    }
    $sql = "SELECT * from ticket t, item i p where i.id = t.item_id";
    $ret = $db->query($sql);
    $array = array();
    while ($data = $ret->fetchArray()) {
        $array[] = $data;
    }
    $db->close();
    return $array;
}
Beispiel #25
0
function update_sleeps($asleep_time, $awakenings, $awake, $light, $deep, $duration)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $date = $_COOKIE['date'];
    $sql = <<<EOF
    SELECT * FROM User,Sleeps WHERE User.name='{$userName}' and User.id=Sleeps.userId and Sleeps.createAt='{$date}';
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $userId = $row['userId'];
            $sql = <<<EOF
            UPDATE Sleeps
            SET asleep='{$asleep_time}',wake_up_time='{$awakenings}',
            sober='{$awake}',light='{$light}',deep='{$deep}',total='{$duration}'
            where userId={$userId} and createAt={$date};
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        } else {
            $userId = get_userId($userName);
            $sql = <<<EOF
            INSERT INTO Sleeps (userId, asleep, wake_up_time, sober, light, deep, total, createAt)
            VALUES ('{$userId}', '{$asleep_time}', '{$awakenings}', '{$awake}', '{$light}', '{$deep}', '{$duration}', '{$date}');
EOF;
            $ret = $db->exec($sql);
            if (!$ret) {
                echo $db->lastErrorMsg();
            } else {
            }
        }
    }
    $db->close();
}
function insert_db($category, $majorCategory, $date)
{
    $dateArr = explode("-", $date);
    if (checkdate($dateArr[1], $dateArr[2], $dateArr[0]) == false) {
        return false;
    }
    $thisdate = mktime(0, 0, 0, $dateArr[1], $dateArr[2], $dateArr[0]);
    $nextdate = $thisdate + 3600 * 24;
    $sql = "select talkid,count(*) as msgcount from allmsg where ";
    if ($category == 0 || $category == 1001 || $category == 1002) {
        $sql .= " channel = {$category}";
    } else {
        $sql .= " channel = 0 and postcategoryid={$category} ";
    }
    if ($majorCategory !== NULL && $majorCategory != 0) {
        $sql .= " and postmajorcategoryid={$majorCategory} ";
    }
    $sql .= " and updatetime >= {$thisdate} and updatetime < {$nextdate} group by talkid order by msgcount desc";
    //echo $sql . '<br/>';
    $db = new MyDB();
    $res = $db->query($sql);
    //初始化关联数组
    $mc["c20"] = $mc["c10"] = $mc["c6"] = $mc["c5"] = $mc["c4"] = $mc["c3"] = $mc["c2"] = $mc["c1"] = 0;
    //分段统计消息数对应的会话数
    while ($result = $db->fetch_assoc($res)) {
        $msgcount = $result["msgcount"];
        if ($msgcount > 20) {
            $mc["c20"]++;
        } else {
            if ($msgcount > 10 && $msgcount <= 20) {
                $mc["c10"]++;
            } else {
                if ($msgcount >= 6 && $msgcount <= 10) {
                    $mc["c6"]++;
                } else {
                    if ($msgcount == 5) {
                        $mc["c5"]++;
                    } else {
                        if ($msgcount == 4) {
                            $mc["c4"]++;
                        } else {
                            if ($msgcount == 3) {
                                $mc["c3"]++;
                            } else {
                                if ($msgcount == 2) {
                                    $mc["c2"]++;
                                } else {
                                    if ($msgcount == 1) {
                                        $mc["c1"]++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //echo json_encode($mc);
    //insert table 'talkcount'
    $sql_insert = "insert into talkcount(analysisdate,postcategoryid,postmajorcategoryid,c20,c10,c6,c5,c4,c3,c2,c1) values('";
    $sql_insert .= $date . "',";
    $sql_insert .= $category . ",";
    $sql_insert .= $majorCategory . ",";
    $sql_insert .= $mc["c20"] . ",";
    $sql_insert .= $mc["c10"] . ",";
    $sql_insert .= $mc["c6"] . ",";
    $sql_insert .= $mc["c5"] . ",";
    $sql_insert .= $mc["c4"] . ",";
    $sql_insert .= $mc["c3"] . ",";
    $sql_insert .= $mc["c2"] . ",";
    $sql_insert .= $mc["c1"] . ")";
    //echo $sql_insert . "\n";
    $db->query($sql_insert);
    $db->close();
}
Beispiel #27
0
class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open("test.db");
    }
}
$db = new MyDB();
if (!$db) {
    echo $db->lastErrorMsg();
} else {
    echo "Database opened successfully\n";
}
if (isset($_POST["task"])) {
    $new = $_POST["task"];
    $uname = $_SESSION["name"];
    $sql = <<<EOF
    INSERT INTO USERS(NAME, TODO)
    VALUES('{$uname}',' {$new}');
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        echo "Record inserted";
    }
    $db->close();
    header('Location: /hey/userpage.php');
} else {
    header('Location: /hey/userpage.php');
}
Beispiel #28
0
function delete()
{
    $db = new MyDB("sqltemptime.db");
    if (!$db) {
        echo $db->lastErrorMsg();
    }
    $name = $_REQUEST["name"];
    $sql = <<<EOF
      DELETE FROM coolingschedule
      WHERE name = "{$name}";
EOF;
    $ret = $db->exec($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        echo "Row deleted";
    }
    $db->close();
}