Ejemplo n.º 1
0
/**
 * count
 * @param Db $db
 * @return array
 */
function getCountRecFood(&$db)
{
    $sql = "select favor,cometrue from recommendedfood,users \n\t\t\twhere recommendedfood.user_id=users.user_id\n\t\t\tand users.school_id={$_POST['school_id']};";
    $res = $db->query($sql);
    if ($res !== false) {
        $return = array();
        $return['count'] = 0;
        $return['wish_satisfied_rate'] = 0.0;
        $return['lineover_rate'] = 0.0;
        $return['line'] = 500;
        //心愿线数量
        $return['count'] = sizeof($res);
        if ($return['count'] === 0) {
            return $return;
        }
        $linecount = 0;
        $truecount = 0;
        foreach ($res as $value) {
            if ($value['cometrue']) {
                $truecount++;
            }
            if ($value['favor'] >= 500) {
                $linecount++;
            }
        }
        $return['lineover_rate'] = $linecount / $return['count'];
        $return['wish_satisfied_rate'] = $truecount / $return['count'];
        return $return;
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    }
}
Ejemplo n.º 2
0
function getReply(&$db, &$value)
{
    $sql = "select content,time from complaint_replies\n\twhere complaint_id={$value['complaint_id']};";
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    } else {
        $value['reply'] = false;
        if (!empty($res)) {
            $value['reply'] = true;
            $value['reply_content'] = $res[0]['content'];
            $value['reply_time'] = $res[0]['time'];
        }
    }
}
Ejemplo n.º 3
0
function getMethod(&$db, &$value)
{
    $sql = "select content,imageurl from foodmethod where recommend_id={$value['recommend_id']} order by sequence;";
    $res = $db->query($sql);
    if ($res !== false) {
        $value['content'] = array();
        $value['imagefile'] = array();
        if (empty($res)) {
            $value['content'] = null;
        }
        foreach ($res as $val) {
            $value['content'][] = $val['content'];
            $value['imagefile'][] = $val['imageurl'];
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    }
}
Ejemplo n.º 4
0
function getAcceptRate(&$db)
{
    $sql = "select count(*) from canteen_complaints where canteen_id={$_POST['canteen_id']};";
    $res = $db->query($sql);
    //食堂投诉数量
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        if ($res[0]['count(*)'] == 0) {
            return 100;
        }
        $sql2 = "select count(*) from canteen_complaints,complaint_replies where \n\t\t canteen_id={$_POST['canteen_id']} and canteen_complaints.complaint_id=complaint_replies.complaint_id;";
        $res2 = $db->query($sql2);
        //食堂回复数
        if ($res2 === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //错误日志
            exit;
        } else {
            if ($res2[0]['count(*)'] == 0) {
                return 0;
            }
            return $res2[0]['count(*)'] / $res[0]['count(*)'];
        }
    }
}
Ejemplo n.º 5
0
                    $sql = "select grade from food_grade where user_id={$_POST['user_id']} and canteen_id={$_POST['canteen_id']} and food_id={$_POST['food_id']};";
                }
            } else {
                echo getJsonResponse(2, "post参数没有设置或错误", null);
                exit;
            }
        } else {
            echo getJsonResponse(2, "url for参数设置错误", null);
            exit;
        }
    }
    //读取数据库
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
    } else {
        if (empty($res)) {
            echo getJsonResponse(0, "成功", null);
            $db->close();
            exit;
        }
        $json = getJsonResponse(0, "成功", $res[0]['grade']);
        $cache->set($cachename, $json, 1200);
        echo $json;
    }
    $db->close();
} else {
    echo getJsonResponse(2, "url for参数没有设置", null);
}
Ejemplo n.º 6
0
function checkExist(&$db, $which)
{
    $sql = '';
    if ($which == 'canteen') {
        $sql = "select count(*) from canteen_grade where user_id={$_POST['user_id']} and canteen_id={$_POST['canteen_id']};";
    } else {
        $sql = "select count(*) from food_grade where user_id={$_POST['user_id']} and canteen_id={$_POST['canteen_id']} and food_id={$_POST['food_id']};";
    }
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        if ($res[0]['count(*)'] == 1) {
            return true;
        } else {
            return false;
        }
    }
}
//if(isset($_SESSION['s_username'])) {
if (!isset($_REQUEST['action'])) {
    $_REQUEST['action'] = "";
}
switch ($_REQUEST['action']) {
    case "getProductDescription":
        if (isset($_REQUEST['productId'])) {
            $response = getJsonResponse($REST_URL . "/api/artigos/" . str_replace('.', '!', $_REQUEST['productId']));
            $response2 = getJsonResponse($REST_URL . "/api/QuantidadeArtigoArmazens/" . str_replace('.', '!', $_REQUEST['productId']));
            $response = array('status' => 'ok', 'articleDescription' => $response, 'articleWarehouses' => $response2);
            echo json_encode($response);
        } else {
            echo json_encode(array('status' => 'error', 'reason' => 'Bad Product ID!'));
        }
        break;
    case "getWarehouseDescription":
        if (isset($_REQUEST['warehouseId'])) {
            $response = getJsonResponse($REST_URL . "/api/armazens/" . str_replace('.', '!', $_REQUEST['warehouseId']));
            $response = array('status' => 'ok', 'warehouseDescription' => $response);
            echo json_encode($response);
        } else {
            echo json_encode(array('status' => 'error', 'reason' => 'Bad Warehouse ID!'));
        }
        break;
    default:
        echo json_encode(array('status' => 'error', 'reason' => 'No Action Set!'));
        break;
}
//}else{
//	echo json_encode(array('status'=>'error', 'reason'=>'Not Logged In!'));
//}
Ejemplo n.º 8
0
                    } else {
                        echo getJsonResponse(0, "成功修改", null);
                    }
                }
                $db->close();
            } else {
                echo getJsonResponse(2, 'post参数没有设置', null);
            }
        } else {
            if ($_GET['content'] == 'sex') {
                if (isset($_POST['user_id']) && isset($_POST['new_sex'])) {
                    $sql = "update users set sex='{$_POST['new_sex']}' where user_id={$_POST['user_id']};";
                    if ($_POST['new_sex'] == '男' || $_POST['new_sex'] == '女') {
                        if (false === $db->execute($sql)) {
                            echo getJsonResponse(1, $db->error, null);
                        } else {
                            echo getJsonResponse(0, "成功修改", null);
                        }
                        $db->close();
                    } else {
                        echo getJsonResponse(2, 'post参数错误,sex', null);
                    }
                } else {
                    echo getJsonResponse(2, 'post参数没有设置', null);
                }
            } else {
                echo getJsonResponse(2, 'url参数错误', null);
            }
        }
    }
}
Ejemplo n.º 9
0
                    if ($db->execute("insert into food_comments_images values({$commentid},'{$savePath}');") === false) {
                        echo getJsonResponse(1, $db->error, null);
                        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
                        $db->rollback();
                        $db->close();
                        exit;
                    }
                } else {
                    //上传图片失败
                    echo getJsonResponse(4, $uf->errorMsg, null);
                    $db->rollback();
                    //回滚
                    $db->close();
                    exit;
                }
            }
        }
        $db->commit();
        echo getJsonResponse(0, "success", array("comment_id" => $commentid));
    } else {
        //插入失败
        echo getJsonResponse(1, $mysqli->error, null);
        $db->rollback();
        //回滚
        Log::error_log('database error:' . $mysqli->error . ' in ' . basename(__FILE__));
    }
    $db->close();
} else {
    echo getJsonResponse(2, "post参数错误", null);
    exit;
}
Ejemplo n.º 10
0
        //计算食物排名
        $food_info = $db->query("select canteens.canteen_id,canteenname,food.food_id,foodname,price,favor,dislike,imageurl,canteen_food.grade\n\t\t\t\t\tfrom canteens,food,canteen_food\n\t\t\t\t\twhere canteens.canteen_id=canteen_food.canteen_id and food.food_id=canteen_food.food_id and \n\t\t\t\t\tcanteen_food.canteen_id in \n\t\t\t\t\t(select canteen_id from school_canteen where school_id={$value['school_id']})\n\t\t\t\t\torder by grade desc limit 0,10;");
        if ($food_info === false) {
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //echo $db->error;
            exit;
        } else {
            if (empty($food_info)) {
                continue;
            }
            foreach ($food_info as &$value3) {
                countComments($db, $value3);
            }
        }
        //usort($food_info,"compare");
        $json2 = getJsonResponse(0, 'success', $food_info);
        $cachename = "ranking.php" . md5("getfood&schoolid={$value['school_id']}") . '.txt';
        $cache->set($cachename, $json2);
        //echo json2;
    }
}
function countfood(&$db, &$value)
{
    $res = $db->query("select count(*) from canteen_food where canteen_id={$value['canteen_id']};");
    if ($res === false) {
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        $db->close();
        exit;
    }
    $value['food_count'] = $res[0]['count(*)'];
}
             $smarty->assign("selected", $_REQUEST['warehouse']);
         }
     } else {
         $warehousesWithArticles = getJsonResponse($REST_URL . '/api/artigosarmazens/' . $_REQUEST['warehouse']);
         $smarty->assign("selected", $_REQUEST['warehouse']);
     }
 } else {
     $warehousesWithArticles = getJsonResponse($REST_URL . '/api/artigosarmazens');
     $smarty->assign("selected", 'none');
 }
 $smarty->assign("articles", $warehousesWithArticles);
 $minValue = 1000000;
 $maxValue = 0;
 $minStock = 1000000;
 $maxStock = 0;
 $articles = getJsonResponse($REST_URL . '/api/artigos');
 foreach ($articles as $article) {
     $value = $article['Preco'];
     $stock = $article['StkAtual'];
     if ($value < $minValue) {
         $minValue = $value;
     }
     if ($value > $maxValue) {
         $maxValue = $value;
     }
     if ($stock < $minStock) {
         $minStock = $stock;
     }
     if ($stock > $maxStock) {
         $maxStock = $stock;
     }
<?php

chdir("common");
require_once "init.php";
//next example will recieve all messages for specific conversation teste
//var_dump($decoded);
if (isset($_SESSION['s_username'])) {
    $smarty->assign("page", "warehouses");
    $smarty->assign("username_session", $_SESSION['s_username']);
    $warehouses = getJsonResponse($REST_URL . '/api/armazens');
    $smarty->assign("warehouses", $warehouses);
    $smarty->display("warehouses.tpl");
} else {
    header('Location: login.php');
}
Ejemplo n.º 13
0
function checkUserName(&$db, $username)
{
    $res = $db->query("select user_id from users where username='******';");
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        $db->close();
        exit;
    }
    if (empty($res)) {
        return false;
    } else {
        return true;
    }
}
<?php

chdir("common");
require_once "init.php";
$temp = str_replace(".", "!", $_POST['emailToRecover']);
$toSend = $REST_URL . '/api/utilizadores/' . $temp . '=BqdNvUKuFTo82lTdQeRuJ1crEvg4ZYt1';
$password = getJsonResponse($toSend);
if ($password['status'] == 'error') {
    $_SESSION['s_error'] = "Email incorreto!";
} else {
    $argMail = $password['status'];
    $to = $_POST['emailToRecover'];
    $subject = "Warehouse Catalog: Recuperacao de palavra-passe";
    $message = "Ola!\n\nEnviamos este email na sequencia do seu pedido para recuperacao da palavra-passe.\n\nA sua password e {$argMail}.\n\n Cumprimentos,\n A Equipa Warehouse Catalog.";
    $from = "*****@*****.**";
    $headers = "From:" . $from;
    mail($to, $subject, $message, $headers);
    $_SESSION['s_ok'] = "Email enviado com sucesso!";
}
header('Location: login.php');
Ejemplo n.º 15
0
function getFavor(&$db, $userid, &$value)
{
    $sql = "select user_id from food_comments_favor where comment_id={$value['comment_id']} and user_id={$userid};";
    $res = $db->query($sql);
    if ($res !== false) {
        if (empty($res)) {
            $value['is_favor'] = false;
        } else {
            $value['is_favor'] = true;
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        exit;
    }
}
Ejemplo n.º 16
0
$db = Db::getInstance();
$cache = new Cache();
try {
    if (($val = $cache->get($cachename)) !== false) {
        echo $val;
        exit;
    } else {
        $db->connect();
        $res = $db->query($sql);
        if ($res === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //错误日志
        } else {
            if (empty($res)) {
                echo getJsonResponse(0, "成功", null);
                $db->close();
                exit;
            }
            $json = getJsonResponse(0, '成功', $res);
            if ($cache->set($cachename, $json, 1200) === false) {
                Log::error_log($cachename . '  ' . $cache->error);
            }
            echo $json;
        }
        $db->close();
    }
} catch (Exception $e) {
    echo getJsonResponse(1, '数据库连接失败', null);
    Log::error_log("数据库连接错误");
}
Ejemplo n.º 17
0
        echo $val;
        exit;
    }
    $sql = "select school_canteen.canteen_id,canteenname,imageurl from school_canteen,canteens \n\t\t\twhere school_id={$_POST['school_id']} and \n\t\t\tschool_canteen.canteen_id=canteens.canteen_id;";
    $db = Db::getInstance();
    try {
        $db->connect();
        $res = $db->query($sql);
        if ($res === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //错误日志
        } else {
            if (!empty($res)) {
                $json = getJsonResponse(0, "成功", $res);
            } else {
                $json = getJsonResponse(0, "成功", null);
            }
            $cache->set($cachename, $json, 1200);
            echo $json;
        }
        $db->close();
    } catch (Exception $e) {
        echo getJsonResponse(1, '数据库连接失败', null);
        Log::error_log("数据库连接错误");
        exit;
    }
} else {
    echo getJsonResponse(2, 'post参数没有设置', null);
    exit;
}
Ejemplo n.º 18
0
try {
    $db->connect();
    if ($db->execute($sql) !== false) {
        if ($db->numRows == 0) {
            echo getJsonResponse(2, "post id错误", null);
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    }
    if ($_GET['which'] == 'comment') {
        if ($db->execute($sql2) !== false) {
            if ($db->numRows == 0) {
                echo getJsonResponse(2, "post id错误", null);
            }
        } else {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            //错误日志
            exit;
        }
    }
    echo getJsonResponse(0, "success", null);
    $db->close();
} catch (Exception $e) {
    echo getJsonResponse(1, "数据库连接错误", null);
    Log::error_log("数据库连接错误");
    exit;
}
Ejemplo n.º 19
0
        $sql = "select * from upgrade where device_id={$_POST['device_id']};";
        $res = $db->query($sql);
        if ($res === false) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        } else {
            if (empty($res)) {
                echo getJsonResponse(2, "id错", null);
            } else {
                if ($res[0]['major_version_number'] > $major || $res[0]['major_version_number'] == $major && $res[0]['minor_version_number'] > $max || $res[0]['major_version_number'] == $major && $res[0]['minor_version_number'] == $max && $res[0]['revision_number'] > $min) {
                    //需要更新
                    $return = array();
                    $return['newversion'] = $res[0]['major_version_number'] . '.' . $res[0]['minor_version_number'] . '.' . $res[0]['revision_number'];
                    $return['apkurl'] = $res[0]['apkurl'];
                    $return['upgrade_content'] = $res[0]['upgrade_content'];
                    echo getJsonResponse(0, "success", $return);
                } else {
                    echo getJsonResponse(3, "版本已为最新", null);
                }
            }
        }
        $db->close();
    } catch (Exception $e) {
        echo getJsonResponse(1, '数据库连接错误', null);
        Log::error_log("数据库连接错误");
        exit;
    }
} else {
    echo getJsonResponse(2, "参数错误", null);
    exit;
}
Ejemplo n.º 20
0
function getNew(&$db, &$value)
{
    $sql = "select time>curdate()-3 from canteen_food where canteen_id={$_POST['canteen_id']} \n\t\t\tand food_id={$value['food_id']};";
    $res = $db->query($sql);
    if ($res === false) {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        //错误日志
        exit;
    } else {
        $value['new'] = $res[0]['time>curdate()-3'];
    }
}
Ejemplo n.º 21
0
                            echo getJsonResponse(1, $db->error, null);
                            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
                            $db->rollback();
                            $db->close();
                            exit;
                        }
                    } else {
                        //上传图片失败
                        echo getJsonResponse(4, $uf->errorMsg, null);
                        $db->rollback();
                        //回滚
                        $db->close();
                        exit;
                    }
                }
            }
        }
        $db->commit();
        echo getJsonResponse(0, "success", array("complaint_id" => $complaint_id));
    } else {
        //插入失败
        echo getJsonResponse(1, $mysqli->error, null);
        $db->rollback();
        //回滚
        Log::error_log('database error:' . $mysqli->error . ' in ' . basename(__FILE__));
    }
    $db->close();
} else {
    echo getJsonResponse(2, "参数没有设置", null);
    exit;
}
Ejemplo n.º 22
0
/**
 * 食物做法步骤
 * @param unknown $db
 * @param unknown $foodid
 * @param unknown $content
 */
function setContent(&$db, $recid, $content, $imagefile)
{
    if ($content == null) {
        return;
    }
    //$method=explode("||", $content);
    $method = json_decode($content, true);
    for ($i = 1; $i <= sizeof($method); $i++) {
        if (empty($imagefile[$i - 1])) {
            $imagefile[$i - 1] = 'http://' . getServerIp() . '/uploads/recommendedfood/default.jpg';
        }
        $sql = "insert into foodmethod values({$recid},{$i},'" . stringToDb($method[$i - 1]) . "','{$imagefile[$i - 1]}');";
        $res = $db->execute($sql);
        if (!$res) {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            $db->rollback();
            $db->close();
            exit;
        }
    }
}