Example #1
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");
        }
    }
}
Example #2
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();
}
Example #3
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();
}
Example #4
0
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");
        }
    }
}
Example #5
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");
}
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;
}
Example #7
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();
}
Example #8
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();
}
Example #9
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();
}
Example #10
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();
}
Example #11
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();
}
Example #12
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();
}
Example #13
0
function napoj_db()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
        return false;
    } else {
        //echo "Opened database successfully<br>"; ///////////////////////////////////
        return $db;
    }
}
Example #14
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();
}
Example #15
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();
}
Example #16
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();
}
Example #17
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();
}
Example #18
0
function get_total_len()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $sql = <<<EOF
    SELECT count(*) AS length FROM Activity;
EOF;
    $ret = $db->query($sql);
    if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
        $db->close();
        return $row['length'];
    }
    $db->close();
    return null;
}
Example #19
0
function show_activity($last, $amount)
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userName = $_COOKIE['username'];
    $userId = get_userId($db, $userName);
    $sql = <<<EOF
    SELECT * FROM Advice WHERE toUserId={$userId} ORDER BY id DESC LIMIT '{$last}','{$amount}';
EOF;
    $ret = $db->query($sql);
    while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
        $authorId = $row['authorId'];
        $authorName = get_authorName($db, $authorId);
        if ($authorName != null) {
            $sayList[] = array('title' => "标题:" . $row['title'], 'content' => "建议内容: " . $row['content'], 'authorName' => "提出者: " . $authorName);
        }
    }
    echo json_encode($sayList);
    $db->close();
}
Example #20
0
<?php

class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('../data/test.db');
    }
}
$db = new MyDB();
if (!$db) {
    echo 'fatal:' . $db->lastErrorMsg();
}
Example #21
0
function analysis()
{
    $db = new MyDB();
    if (!$db) {
        echo $db->lastErrorMsg();
    } else {
    }
    $userId = get_userId($db);
    //moves
    $sql = <<<EOF
    SELECT sum(steps),count(createAt) FROM Moves WHERE userId={$userId};
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $total_steps = $row['sum(steps)'];
            $times = $row['count(createAt)'];
            $avg_steps = number_format($total_steps / $times, 2, '.', '');
        }
    }
    //sleeps
    $sql = <<<EOF
    SELECT sum(total),count(createAt) FROM Sleeps WHERE userId={$userId};
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $total_sleeps = $row['sum(total)'];
            $times = $row['count(createAt)'];
            $avg_sleep = number_format($total_sleeps / $times, 2, '.', '');
        }
    }
    //workouts
    $sql = <<<EOF
    SELECT sum(distance),count(createAt) FROM Workouts WHERE userId={$userId};
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $total_run = $row['sum(distance)'];
            $times = $row['count(createAt)'];
            $avg_run = number_format($total_run / $times, 2, '.', '');
        }
    }
    //meals
    $total_fat = 0;
    $total_protein = 0;
    $total_calcium = 0;
    $total_carbohydrate = 0;
    $total_sugar = 0;
    $total_cholesterol = 0;
    $total_vitamin_c = 0;
    $total_vitamin_a = 0;
    $sql = <<<EOF
    SELECT sum(fat),sum(protein),
    sum(calcium),sum(carbohydrate),
    sum(sugar),sum(cholesterol),
    sum(vitamin_c),sum(vitamin_a) FROM Meals WHERE userId={$userId};
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        if ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $total_fat = $row['sum(fat)'];
            $total_protein = $row['sum(protein)'];
            $total_calcium = $row['sum(calcium)'];
            $total_carbohydrate = $row['sum(carbohydrate)'];
            $total_sugar = $row['sum(sugar)'];
            $total_cholesterol = $row['sum(cholesterol)'];
            $total_vitamin_c = $row['sum(vitamin_c)'];
            $total_vitamin_a = $row['sum(vitamin_a)'];
        }
    }
    //mood
    $amazing = 0;
    $very_good = 0;
    $good = 0;
    $usual = 0;
    $bad = 0;
    $very_bad = 0;
    $fuck_dog = 0;
    $sql = <<<EOF
    SELECT mood FROM Mood WHERE userId={$userId};
EOF;
    $ret = $db->query($sql);
    if (!$ret) {
        echo $db->lastErrorMsg();
    } else {
        while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
            $mood_type = $row['mood'];
            if ($mood_type == "../../img/Amazing.png") {
                $mood_type = 1;
            } else {
                if ($mood_type == "../../img/Pumped_UP.png") {
                    $mood_type = 2;
                } else {
                    if ($mood_type == "../../img/Energized.png") {
                        $mood_type = 3;
                    } else {
                        if ($mood_type == "../../img/Meh.png") {
                            $mood_type = 4;
                        } else {
                            if ($mood_type == "../../img/Dragging.png") {
                                $mood_type = 5;
                            } else {
                                if ($mood_type == "../../img/Exhausted.png") {
                                    $mood_type = 6;
                                } else {
                                    if ($mood_type == "../../img/Totally_Done.png") {
                                        $mood_type = 7;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            switch ($mood_type) {
                case 1:
                    $amazing++;
                    break;
                case 2:
                    $very_good++;
                    break;
                case 3:
                    $good++;
                    break;
                case 4:
                    $usual++;
                    break;
                case 5:
                    $bad++;
                    break;
                case 6:
                    $very_bad++;
                    break;
                case 7:
                    $fuck_dog++;
                    break;
            }
        }
    }
    echo "\n        <div class='col-md-12'>\n            <div id='analysis-moves'>\n                <div style='margin-left: 10%'>\n                    <h3>你总共走了 <strong style='color: white'>{$total_steps}</strong> 步,平均每天走了 <strong style='color: white'>{$avg_steps}</strong> 步</h3>\n                </div>\n            </div>\n            <div id='analysis-sleeps'>\n                <div style='margin-left: 10%'>\n                    <h3>你总共睡了 <strong style='color: white'>{$total_sleeps}</strong> 小时,平均每天睡了 <strong style='color: white'>{$avg_sleep}</strong> 小时</h3>\n                </div>\n            </div>\n            <div id='analysis-workouts'>\n                <div style='margin-left: 10%'>\n                    <h3>你总共跑了 <strong style='color: white'>{$total_run}</strong> 公里,平均每天跑了 <strong style='color: white'>{$avg_run} </strong> 公里</h3>\n                </div>\n            </div>\n            <div id='analysis-meals'>\n                <div style='margin-left: 10%'>\n                    <h4>共摄入 <strong style='color: white'>{$total_fat}</strong> 克脂肪</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_protein}</strong> 毫克蛋白质</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_calcium}</strong> 毫克钙</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_carbohydrate}</strong> 毫克碳水化合物</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_sugar}</strong> 毫克糖</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_cholesterol}</strong> 毫克胆固醇</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_vitamin_c}</strong> 毫克维他命C</h4>\n                    <h4>共摄入 <strong style='color: white'>{$total_vitamin_a}</strong> 毫克维他命A</h4>\n\n                </div>\n            </div>\n            <div id='analysis-mood'>\n                <div style='margin-left: 10%'>\n                    <h3>心情状况为</h3>\n                    <h4>“Amazing好” <strong style='color: white'>{$amazing}</strong> 次</h4>\n                    <h4>“非常好” <strong style='color: white'>{$very_good}</strong> 次</h4>\n                    <h4>“好” <strong style='color: white'>{$good}</strong> 次</h4>\n                    <h4>“一般” <strong style='color: white'>{$usual}</strong> 次</h4>\n                    <h4>“坏” <strong style='color: white'>{$bad}</strong> 次</h4>\n                    <h4>“非常坏” <strong style='color: white'>{$very_bad}</strong> 次</h4>\n                    <h4>“槽糕透了” <strong style='color: white'>{$fuck_dog}</strong> 次</h4>\n                </div>\n            </div>\n        </div>\n    ";
}
$booksdb = new MyDB(BOOKS_DATABASE_FILE);
if (!$booksdb) {
    echo $booksdb->lastErrorMsg();
}
$res = $booksdb->query("\n\t\t\tSELECT\n\t\t\t\tZASSETID,\n\t\t\t\tZTITLE AS Title,\n\t\t\t\tZAUTHOR AS Author\n\t\t\tFROM ZBKLIBRARYASSET\n\t\t\tWHERE ZTITLE IS NOT NULL");
while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
    $books[$row['ZASSETID']] = $row;
}
$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;
Example #23
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();
}
Example #24
0
				<th>Notes</th>
			</tr>
		</thead>
		<tbody>

<?php 
class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('starwars_media.db');
    }
}
$db = new MyDB();
if (!$db) {
    print $db->lastErrorMsg();
} else {
}
$sql = $db->prepare("\n     SELECT mid,\n          \ttitle,\n          \tpid,\n          \tpublish_date,\n          \tyear,\n          \tepid,\n          \terid,\n          \tcid,\n          \ttid,\n          \thave,\n          \treference,\n          \tedition,\n          \tnotes\n       FROM media;");
$ret = $sql->execute();
while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
    $mid = $row['mid'];
    $rsql = "SELECT fullname\n                 FROM author\n                WHERE aid = (SELECT aid\n                               FROM media_author\n                              WHERE mid = {$mid})";
    $rret = $db->query($rsql);
    $author_list = '';
    while ($rrow = $rret->fetchArray(SQLITE3_ASSOC)) {
        $author_list .= $rrow['fullname'];
    }
    $pid = $row['pid'];
    $publisher = '';
    if ($pid != '') {
Example #25
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;
}
Example #26
0
        </div>
        </div>
        </div>
    </div>
        <?php 
// CONNECT TO THE DATA BASE
class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('2016.db');
    }
}
$db = new MyDB();
if (!$db) {
    echo $db->lastErrorMsg();
} else {
    echo "[[Opened database successfully YAY!!!]]";
}
//require 'db_functions.php';
$feedback = $_POST['commentBox'];
$email = $_POST['email'];
//Convert whitespaces and underscore to dash
//$feedback = preg_replace("/[\s_]/", "_", $feedback);
//$email = preg_replace('/@/', '^', $email);
$insert = "INSERT INTO feedback (feedback, email) VALUES ('" . $feedback . "','" . $email . "');";
$ret = $db->prepare($insert);
if (!$ret) {
    echo "<p>" . $db->lastErrorMsg() . "<p>";
} else {
    echo "Records created successfully\n";
Example #27
0
    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'))));
    }
Example #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();
}
Example #29
0
<?php

date_default_timezone_set("Asia/Shanghai");
session_start();
class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('../../fitdayDB.db');
    }
}
$db = new MyDB();
if (!$db) {
    echo $db->lastErrorMsg();
}
$type = $_GET['type'];
if ($type == "top3") {
    getTop3($db);
}
if ($type == "rank") {
    getRank($db);
}
if ($type == "timeline") {
    $pagenum = $_GET['page'];
    getPageN($pagenum, $db);
}
function getRank($db)
{
    $userid = $_SESSION['users'];
    $nowdate = date('Y-m-d', time());
    $datetime = strtotime(date("Y-m-d", time()));
Example #30
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;
}