Exemple #1
0
                            Initialize data.
                        </button>
                    </div>

                </div>
            </div>
            <hr>
            <div class="row">
                <div class="col-md-3">
                    <?php 
    $lastCreation = $metaController->getSearchMetaRecent();
    $lastCreationDate = "2014-01-01";
    if ($lastCreation) {
        $lastCreationDate = $lastCreation['date'];
    }
    $poiCount = $poiController->countByDate($lastCreationDate);
    ?>
                    <h4 class="box-title">Create new search data file</h4>
                    <p><b><?php 
    echo $poiCount;
    ?>
</b>&nbsp; pois have been updated or added.</p>
                    <i>The new search data will contain only new and updated data after the last creation of the search
                        data file.</i>
                    <br>
                    <br>
                    <a href="<?php 
    echo Route::getAdminDirectory();
    ?>
service/prepare.php">
                        <button class="btn btn-primary"
header('Content-Type: text/event-stream');
// recommended to prevent caching of event data.
header('Cache-Control: no-cache');
$userController = new UsersController();
$userId = $_SESSION['userId'];
$user = $userController->find($userId);
if ($user->getPrevilege() == 1) {
    $metaController = new MetaController();
    $poiController = new PoiController();
    //get the last date of creation of search file
    $lastCreation = $metaController->getSearchMetaRecent();
    $lastCreationDate = "2014-01-01";
    if ($lastCreation) {
        $lastCreationDate = $lastCreation['date'];
    }
    $totalPois = $poiController->countByDate($lastCreationDate);
    if ($totalPois > 0) {
        //create the file name and the url for the route
        $path = "../../assets/files/search/";
        $filename = "sdf_" . date('Ymd') . ".txt";
        $completePath = $path . $filename;
        $url = Route::getAdminDirectory() . "assets/files/search/" . $filename;
        $outputFile = fopen($completePath, "w");
        if ($outputFile) {
            $insertCount = 0;
            $tableName = $poiController->getTableName();
            /* create database connection here */
            $sql = "SELECT poi.*,u.*,sub.*,sup.*,\n                poi.id as pId,poi.category as poiCategory, poi.date as poiDate,poi.email as poiEmail,\n                u.id as uId,u.email as userEmail,\n                sub.id as subId,sub.date as subDate,sub.userId as subUid,\n                sup.id as supId, sup.date as supDate,sup.userId as supUid,sup.category as supCategory\n                FROM " . $tableName . " as poi\n                INNER JOIN vt_users as u ON poi.userId = u.id\n                INNER JOIN vt_mymap_subcategory as sub ON poi.category = sub.id\n                INNER JOIN vt_mymap_category as sup ON sub.superCategory = sup.id\n                WHERE poi.update_date > '{$lastCreationDate}'\n                ORDER BY poi.update_date DESC";
            if ($result = mysql_query($sql, $poiController->getConnection())) {
                if (mysql_num_rows($result) > 0) {
                    /* iterate through the results */