Ejemplo n.º 1
0
function main()
{
    $archivo = 'csvDelitos.csv';
    if ($_POST["action"] == "upload") {
        if (copy($_FILES['archivo']['tmp_name'], "files/txt/" . $archivo)) {
            $status = "Archivo subido: <b>" . $archivo . "</b>";
            $bStatus = True;
        } else {
            $status = "Error al subir el archivo";
        }
    }
    $listaValores = readCSV($archivo);
    $_SESSION['fecha'] = $listaValores[0];
    //array
    $_SESSION['valores'] = $listaValores[1];
    //array
    $fileFechas = createFile('fechas', $listaValores[0]);
    //creamos archivo de fechas
    $fileValores = createFile('valores', $listaValores[1]);
    //creamos archivo de valores
    //echo '<br/>'.implodeFecha();
    //echo '<br/>'.implodeValores();
    //echo '<br/>'.countValores();
    //echo '<br/>'.callPython($fileValores);
    //echo '<br/>'.callNormalizar($fileValores);
    $_SESSION['normalizar'] = callNormalizar($fileValores);
    //String
    unlink('files/txt/' . $archivo);
    //eliminamos el archivo creado
    createCSV($archivo, $listaValores[2]);
}
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //        $this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
     foreach (readCSV() as $key => $person) {
         $this->sendMail($person, $key);
     }
 }
Ejemplo n.º 3
0
function getRegion($region = "", $json)
{
    $jsonObj = json_decode($json);
    //die(print_r($jsonObj));
    $regionsArr = array();
    // 0 => array ( "code" => "gr", name => "Greece" )
    $airports = readCSV();
    //print_r($airports);
    foreach ($airports as $k => $v) {
        if ($v[region][code] == $region) {
            $flag = true;
            foreach ($regionsArr as $k2 => $v2) {
                if ($v2[code] == $v[country][code]) {
                    $flag = false;
                    break;
                }
            }
            if ($flag) {
                $regionsArr[] = array("code" => $v[country][code], "name" => $v[country][name]);
            }
        }
    }
    $regionJsonObj = new stdClass();
    //print_r($regionsArr);
    foreach ($regionsArr as $k3 => $v3) {
        $flag = false;
        foreach ($jsonObj->pathes as $id => $obj2) {
            if (mb_strtolower($v3[name], 'UTF-8') == mb_strtolower($obj2->name, 'UTF-8')) {
                $flag = true;
                $regValObj = new stdClass();
                $innerObj = new stdClass();
                $myId = $v3[code];
                $innerObj->path = $obj2->path;
                $innerObj->name = $obj2->name;
                $regionJsonObj->pathes->{$myId} = $innerObj;
            }
        }
        if (!$flag) {
            echo "{$v3['name']} not found\n";
        }
    }
    echo "\n\n ---------------------------------- \n\n";
    foreach ($jsonObj->pathes as $id => $obj2) {
        echo "{$obj2->name} \n";
    }
    print_r(json_encode($regionJsonObj));
}
Ejemplo n.º 4
0
function writeFile($path, $pemisah)
{
    global $jenisdata;
    $dir = $path;
    $ext = explode('.', basename($_FILES['filex']['name']));
    $ext = $ext[count($ext) - 1];
    $ext = strtolower($ext);
    if ($ext == 'csv') {
        $path = $dir . "/" . date('ymd') . "." . $ext;
        @unlink($path);
        try {
            if (move_uploaded_file($_FILES['filex']['tmp_name'], $path)) {
                $x = readCSV($path, $pemisah);
                simpanData($x, $jenisdata);
            }
        } catch (Exception $e) {
            echo "<script>alert(\"Error Writing File" . addslashes($e->getMessage()) . "\");</script>";
        }
    } else {
        echo "<script>alert('Filetype not support" . basename($_FILES['filex']['name']) . "__" . $path . "');</script>";
    }
}
Ejemplo n.º 5
0
function main($dir, $colname, $reload, $csvonly)
{
    $xlsx_njs = "./js/node_modules/xlsx/bin/xlsx.njs";
    echo $dir;
    $d = dir($dir);
    while (false !== ($entry = $d->read())) {
        if (!is_dir($dir . $entry) && endsWith($entry, ".xls")) {
            $csvFile = "{$entry}.csv";
            if (file_exists($dir . $csvFile)) {
                if ($reload == 1) {
                    echo "{$csvFile} already exist. Reload it!\n";
                    // process generated CSV
                    readCSV($dir, $csvFile, $colname);
                } else {
                    echo "{$csvFile} already exist. Skip it!\n";
                }
            } else {
                echo "working on {$csvFile}...\n";
                $snames = getSheetNames($xlsx_njs, $dir, $entry);
                foreach ($snames as $key => $sname) {
                    if ($key == 0) {
                        $sysStr = "{$xlsx_njs} '{$dir}/{$entry}' {$sname} > '{$dir}/{$csvFile}'";
                    } else {
                        $sysStr = "{$xlsx_njs} '{$dir}/{$entry}' {$sname} >> '{$dir}/{$csvFile}'";
                    }
                    echo "Writing CSV for {$sname} \n";
                    system($sysStr);
                }
                if ($csvonly) {
                    continue;
                }
                // process generated CSV
                readCSV($dir, $csvFile, $colname);
            }
        }
    }
    $d->close();
}
Ejemplo n.º 6
0
 public function __construct()
 {
     $this->users = readCSV('users.csv');
 }
Ejemplo n.º 7
0
<?php

function readCSV($file)
{
    $f = file($file);
    foreach ($f as $k) {
        $csv[] = explode("\t", $k);
    }
    return $csv;
}
$lines = readCSV("data/objectcodes.tsv");
foreach ($lines as $line) {
    echo "<tr class= \"result\">\n";
    foreach ($line as $item) {
        echo "<td>" . $item . "</td>";
    }
    echo "</tr>\n";
}
Ejemplo n.º 8
0
    } else {
        $action2 = $allowedAction2[$action][0];
    }
}
/**
		1. Traitement des données
	**/
if ($action == 'batch') {
    // Traitement des CSV importés
    if ($action2 == 'import' && count($_POST) > 0) {
        // Si fichier CSV envoyé
        if (isset($_POST['upload']) && isset($_FILES['csv']) && $_POST['upload'] == 'ok') {
            $fileName = explode('.', $_FILES['csv']['name']);
            if (is_file($_FILES['csv']['tmp_name']) && ($csv = fopen($_FILES['csv']['tmp_name'], 'r') && $fileName[count($fileName) - 1] == 'csv')) {
                // Récupération de la liste à partir du CSV
                $affectations = readCSV($_FILES['csv']['tmp_name'], ';', FALSE);
                /* On parcours le fichier $affectations et :
                 *	   - On enregistre dans l'array $affectationsOk['insert'] les valeurs  prêtes à être insérées
                 *    - On enregistre dans l'array $affectationsOk['erreur'] les valeurs qui posent probleme et qui ne doivent pas être insérées
                 */
                $affectationOk['insert'] = array();
                $affectationOk['erreur'] = array();
                foreach ($affectations as $affectationId => $affectationData) {
                    if (count($affectationData) >= 4) {
                        $erreurAffectation = checkAffectationInsertData(getUserIdFromNbEtudiant($affectationData[0]), $affectationData[1], $affectationData[2], $affectationData[3], array());
                        if (count($erreurAffectation) == 0) {
                            $affectationOk['insert'][$affectationId] = array('etudiant' => getUserIdFromNbEtudiant($affectationData[0]), 'service' => $affectationData[1], 'dateDebut' => $affectationData[2], 'dateFin' => $affectationData[3]);
                        } else {
                            $affectationOk['erreur'][$affectationId] = $erreurAffectation;
                        }
                    }
Ejemplo n.º 9
0
 function get_data()
 {
     global $CFG, $COURSE, $USER;
     $data = parent::get_data();
     if (!$data) {
         return false;
     }
     if (isset($data->usecsvimport)) {
         // Set options from csv
         $usercontext = get_context_instance(CONTEXT_USER, $USER->id);
         $fs = get_file_storage();
         if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $data->csvfile, 'sortorder, id', false))) {
             return false;
         }
         if (count($files) != 1) {
             return false;
         }
         $csvfile = reset($files);
         $csv = readCSV($csvfile->get_content_file_handle(), true);
         // Manipulate $data to reflect form content (options, limit, grouping, optionid)
         $data = options_from_csv($data, $COURSE->id, $csv);
     }
     // Set up completion section even if checkbox is not ticked
     if (empty($data->completionsection)) {
         $data->completionsection = 0;
     }
     return $data;
 }
Ejemplo n.º 10
0
    }
    if ($bStatus) {
        return $destino;
    } else {
        return $bStatus;
    }
    // De lo contrario un false
}
//function main()
if ($_POST["action"] == "upload") {
    $archivoDestino = uploadFile();
    //Subimos el archivo CVS
    if (!$archivoDestino) {
        die;
    }
    $archivoLimpio = readCSV($archivoDestino);
    //Pasamos el archivo CSV a un .txt que es una simple lista //Regresa un array de dos elementos, destino y la lista de los elementos
    $valoresY = implode(",", $archivoLimpio[1]);
    $valoresX = implode(",", $archivoLimpio[2]);
    //El de las fechas
    /*$max = max($archivoLimpio[1]); //Escalar en php es mala idea..!
    //$min = min($archivoLimpio[1]);
    $min = "0";
    $escalada = $archivoLimpio[1];
    $nueva = array();
    //echo implode(",", $escalada)."<br/>";
    //echo $max."..".$min."..";
    
    for($i = 0; $i < count($escalada); $i++)
    {
      //echo "".$escalada[$i]."...";
Ejemplo n.º 11
0
    } else {
        // successful
        echo $OUTPUT->notification(get_string('csv-import-success', 'groupreg'), 'notifysuccess');
    }
} else {
    if (!isset($_FILES['csvupload']) || $_FILES['csvupload']['size'] == 0) {
        // Output the confirmation form
        echo $renderer->display_import_assignment_form($cm, $action);
    } else {
        if ($_FILES['csvupload']['error'] > 0) {
            echo $OUTPUT->notification("Error: " . $_FILES["csvupload"]["error"]);
            echo $renderer->display_import_assignment_form($cm, $action);
        } else {
            // Move uploaded file, display contents to verify
            $filedest = tempnam("/tmp", "groupreg-importcsv");
            move_uploaded_file($_FILES["csvupload"]["tmp_name"], $filedest);
            // Verify contents, print result
            $csv = readCSV($filedest, false, ';');
            $errors = verifyCSV($csv, $action, $choice, $cm);
            if (isset($errors) && is_array($errors) && sizeof($errors) > 0) {
                //echo $OUTPUT->notification(implode("<br/>", $errors));
                show_errors($errors);
                echo $renderer->display_import_assignment_form($cm, $action);
            } else {
                // Verified, print table and continue
                echo display_csv_contents($cm, $filedest, $action, ';');
            }
        }
    }
}
echo $OUTPUT->footer();
/* ================================================================
 *  
 *  @author : Régis Robineau
 *  @project : Equipex Biblissima
 *  @description : output a workable image sequence out of a basic 
 *  list of image urls. Retrieve w/h via info.json (IIIF Image API)
 *
 * ================================================================
*/
// Input file
$csvInputFile = "input/Lyon-0604-liens.csv";
// Output file
$csvOutputFile = "input/sequences_iiif/Lyon-0604-sequence.csv";
// Read csv input file
$csvInputData = readCSV($csvInputFile);
// Create empty array for the list of images (url, label)
$imgData = array();
// Loop through csv data
foreach ($csvInputData as $item) {
    // Set image label
    if ($item[8] !== ".JPG.tif") {
        $rv = strtolower($item[8]);
        $label = $item[7] . $rv;
    } else {
        $label = $item[7];
    }
    $img = array();
    $img["label"] = $label;
    //array_push($img, $label);
    // Set image url
Ejemplo n.º 13
0
  </div>
  <!-- /#mapMenu -->
  <div class="mapBody">
  <div class="leftCol">
    <div class="af map"></div>
    <div class="as map"></div>
    <div class="cr map"></div>
    <div class="ca map"></div>
    <div class="eu map" style="display:block;"></div>
    <div class="na map"></div>
    <div class="oc map"></div>
    <div class="sa map"></div>
  </div>
  <div class="rightCol">
    <h3>Europe</h3>
    <div id="autoCompleteWrapper">
      <?php 
    $airports = readCSV();
    echo getCountries('eu', $airports);
    ?>
    </div>
    <div id="autoItemsWrapper"></div>
  </div>
</div>
</div>
<!-- / #airportsByMap -->

</body>
</html>
<?php 
}
Ejemplo n.º 14
0
/**
		2. Traitement des donnés
	**/
if ($action == 'importCSVFile') {
    // Téléchargement du CSV vide
    if (isset($_GET['downloadCSV'])) {
        $arrayCSV[] = array(LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_NOM, LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_PRENOM, LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_MAIL, LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_NBETU, LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_PROMOTION, LANG_ADMIN_UTILISATEURS_MENU_BATCH_TABLE_RANG);
        downloadCSV($arrayCSV, 'import.csv');
    }
    // Traitement des CSV importés
    // Si fichier CSV envoyé
    if (isset($_POST['upload']) && isset($_FILES['csv']) && $_POST['upload'] == 'ok') {
        $fileName = explode('.', $_FILES['csv']['name']);
        if (is_file($_FILES['csv']['tmp_name']) && ($csv = fopen($_FILES['csv']['tmp_name'], 'r') && $fileName[count($fileName) - 1] == 'csv')) {
            // Récupération de la liste à partir du CSV
            $users = readCSV($_FILES['csv']['tmp_name'], ';', FALSE);
            // Corresponsance CSV -> Valeur
            $correspondance = array('nom' => 0, 'prenom' => 1, 'mail' => 2, 'nbEtu' => 3, 'promotion' => 4, 'rang' => 5);
            /* On parcours le fichier $users et :
             *	   - On enregistre dans l'array $userOK['insert'] les valeurs  prêtes à être insérées
             *	   - On enregistre dans l'array $userOK['update'] les valeurs  prêtes à être mises à jours
             *    - On enregistre dans l'array $userOK['erreur'] les valeurs qui posent probleme et qui ne doivent pas être insérées
             */
            $userOK['insert'] = array();
            $userOK['update'] = array();
            $userOK['erreur'] = array();
            foreach ($users as $usersId => $usersData) {
                $userData = array();
                foreach ($usersData as $key => $value) {
                    // On transforme la structure des mails
                    if (array_search($key, $correspondance) == 'mail') {
Ejemplo n.º 15
0
$accessToken = "4DK3_Q9x-YAAAAAAAAAAS-tnAaiFa42LXEBW2PIWTO4QpfVfMSVtf1kxAhf_WFU3";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
//list directory of dropbox
$folderMetadata = $dbxClient->getMetadataWithChildren("/");
// Set path to CSV file
$f = fopen($first_csv_file, "w+b");
$csv1_meta = $dbxClient->getFile("/" . $first_csv_file, $f);
fclose($f);
//Set path to CSV file
$f = fopen($second_csv_file, "w+b");
$csv2_meta = $dbxClient->getFile("/" . $second_csv_file, $f);
fclose($f);
$csv1 = readCSV($first_csv_file);
//Set path to CSV file
$csvFile = $second_csv_file;
$csv2 = readCSV($csvFile);
foreach ($csv1 as $s) {
    $array = array();
    $array[] = $s[0];
    $array[] = $s[2];
    $array[] = $s[4];
    $array[] = $s[5];
    $abc[] = $array;
}
$i = 0;
foreach ($csv2 as $s1) {
    $array = array();
    $abc[$i][] = $s1[0];
    $abc[$i][] = $s1[2];
    $abc[$i][] = $s1[3];
    $i++;
Ejemplo n.º 16
0
function makeD3Readable($tree)
{
    $d3Tree = [];
    foreach ($tree as $key => $value) {
        if (is_array($value)) {
            $object = [];
            $object['name'] = $key;
            $object['children'] = makeD3Readable($value);
            $d3Tree[] = $object;
        } else {
            $leave = [];
            $leave['name'] = $key;
            $leave['size'] = $value;
            $d3Tree[] = $leave;
        }
    }
    return $d3Tree;
}
function wrap($tree)
{
    $d3Tree = [];
    $d3Tree['name'] = 'Begroting';
    $d3Tree['children'] = $tree;
    return $d3Tree;
}
$csv = readCSV();
$data = cleanAndConvert($csv);
$tree = convertToTree($data);
$completeTree = fillMissing($tree);
//$output = wrap(makeD3Readable($completeTree));
echo json_encode($completeTree, JSON_UNESCAPED_UNICODE);
Ejemplo n.º 17
0
                    <th>Industry</th>
                </tr>
            </thead>
            <tbody>
                <?php 
function readCSV($csvFile)
{
    $file_handle = fopen($csvFile, 'r');
    while (!feof($file_handle)) {
        $line_of_text[] = fgetcsv($file_handle, 1024);
    }
    fclose($file_handle);
    return $line_of_text;
}
$csvFile = 'includes/companylist.csv';
$csv = readCSV($csvFile);
for ($i = 1; $i < sizeof($csv); $i++) {
    echo "<tr>";
    echo "<td>", $csv[$i][0], "</td>";
    echo "<td>", $csv[$i][1], "</td>";
    echo "<td>", $csv[$i][2], "</td>";
    echo "<td>", $csv[$i][3], "</td>";
    echo "<td>", $csv[$i][4], "</td>";
    echo "<td>", $csv[$i][5], "</td>";
    echo "<td>", $csv[$i][6], "</td>";
    echo "</tr>";
}
echo "</tbody>";
?>
            </tbody>
        </table>
Ejemplo n.º 18
0
function import_assignments_from_csv($groupreg, $file, $cm)
{
    global $DB;
    $csv = readCSV($file, false, ';');
    if (!$csv) {
        return array('csvimport-error-file-not-there::' . $file);
    }
    $data = parse_assignment_csv($csv, $groupreg, $cm);
    if (sizeof($data->errors) > 0) {
        return;
    }
    // cancel importing if there are errors.
    // reset existing assignments
    groupreg_reset_assignment($groupreg);
    // import new assignments into database
    foreach ($data->assignments as $asgn) {
        $DB->insert_record('groupreg_assigned', $asgn);
    }
    $groupreg->timeclose = time();
    $groupreg->timemodified = time();
    $groupreg->allowupdate = 0;
    $groupreg->assigned = 1;
    $DB->update_record("groupreg", $groupreg);
}
         $reader->setReadDataOnly(true);
         $path = UPLOAD_DIR . $name;
         $excel = $reader->load($path);
         $writer = PHPExcel_IOFactory::createWriter($excel, 'CSV');
         $writer->save('data.csv');
         function readCSV($csvFile)
         {
             $file_handle = fopen($csvFile, 'r');
             while (!feof($file_handle)) {
                 $line_of_text[] = fgetcsv($file_handle, 1024);
             }
             fclose($file_handle);
             return $line_of_text;
         }
         $csvFile = 'data.csv';
         $data = readCSV($csvFile);
         $row = 0;
         foreach ($data as $fields) {
             $row++;
         }
         $column = count($data[0]);
         for ($i = 2; $i < $row; $i++) {
             $fid = $data[$i][0];
             $marks = $data[$i][1];
             //$sql2="SELECT * FROM faculty WHERE usn='$usn' and sub='$sub1'";
             //$check2=mysql_query($sql2);
             $sql = " update  assignment set submission='{$marks}' WHERE usn='{$fid}' AND subject='{$res['4']}'";
             $check = mysql_query($sql);
         }
     }
 }
Ejemplo n.º 20
0
<?php

require "vendor/autoload.php";
function readCSV($file)
{
    $rows = [];
    $handle = fopen($file, "r");
    while (!feof($handle)) {
        $rows[] = fgetcsv($handle);
    }
    fclose($handle);
    return $rows;
}
$authors = array_filter(readCSV("authors.csv"));
$categories = array_filter(readCSV("categories.csv"));
$posts = array_filter(readCSV("posts.csv"));
function filterByColumn($array, $column, $value)
{
    return array_filter($array, function ($item) use($column, $value) {
        return $item[$column] == $value;
    });
}
$authors = array_map(function ($author) use($posts) {
    $author["posts"] = filterByColumn($posts, 1, $author[0]);
    // perform other changes to $author
    return $author;
}, $authors);
$categories = array_map(function ($category) use($posts) {
    $category["posts"] = filterByColumn($posts, 2, $category[0]);
    // perform other changes to $category
    return $category;