Example #1
0
File: func.php Project: hejibo/usee
function LOGFILE()
{
    $file = $_SERVER['DOCUMENT_ROOT'] . '/runtime.log';
    defined('RN') || define('RN', "\r\n");
    if (!is_file($file)) {
        return false;
    }
    file_put_contents($file, udate('Y-m-d H:i:s.u T') . RN, FILE_APPEND);
    $data = func_get_args();
    $content = '';
    foreach ($data as $d) {
        $content .= is_array($d) || is_object($d) || is_bool($d) ? json_encode($d) : $d;
        $content .= RN;
    }
    file_put_contents($file, $content . RN, FILE_APPEND);
}
Example #2
0
//if($db)
//  echo "Polaczono ...<br/>";
//else
//  echo "Nie mozna sie polaczyc<br/>";
$query = 'SELECT prze.nazwa FROM przepisy prze, produkty pro, polaczenie p WHERE pro.id_prod= ' . $skladnik1 . ' AND p.id_prod=pro.id_prod AND p.id_przep = prze.id_przep;';
$result = pg_query($query) or die('Nieprawidłowe zapytanie: ' . pg_last_error());
function udate($format, $utimestamp = null)
{
    if (is_null($utimestamp)) {
        $utimestamp = microtime(true);
    }
    $timestamp = floor($utimestamp);
    $milliseconds = round(($utimestamp - $timestamp) * 1000000);
    return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp);
}
$data = udate('Y-m-d H:i:s.u');
// 19:40:56.78128
//echo $data;
while ($line = pg_fetch_row($result)) {
    echo $line[0];
    echo '<input type="hidden" value="' . $line[0] . '" name="nazwa" />';
    echo '<input type="hidden" value="' . $data . '" name="data" />';
}
?>
	
</div>
			<div class="tresc">
<h3>Treść starego przepisu:</h3>

<?php 
$query = 'SELECT prze.przepis FROM przepisy prze, produkty pro, polaczenie p WHERE pro.id_prod= ' . $skladnik1 . ' AND p.id_prod=pro.id_prod AND p.id_przep = prze.id_przep; ';
 public function generate_backup($user, $backup)
 {
     //generates a backup according to submitted parameters.
     if (!$user->loggedIn($this)) {
         return array('location' => 'main.php', 'status' => 'Please log in to generate backups.', 'class' => 'error');
     }
     if (!isset($backup['contents']) || !is_array($backup['contents']) || count($backup['contents']) < 1) {
         return array('location' => 'backup.php', 'status' => 'Please select at least one option for backup contents.');
     }
     if (!isset($backup['action']) || !is_array($backup['action']) || count($backup['action']) < 1) {
         return array('location' => 'backup.php', 'status' => 'Please select at least one place to save backup contents.');
     }
     //create the individual backup files.
     $output_files = array();
     $timestamp = udate('Y-m-d-H-i-s-u');
     foreach ($backup['contents'] as $content) {
         switch ($content) {
             case 'database':
                 $backup_file_name = 'backup-database-' . $timestamp . '.sql';
                 exec('mysqldump -u' . addslashes(MYSQL_USERNAME) . ' -p' . addslashes(MYSQL_PASSWORD) . ' --ignore-table=' . addslashes(MYSQL_DATABASE) . '.users ' . addslashes(MYSQL_DATABASE) . ' > ' . APP_ROOT . '/backups/' . $backup_file_name, $file_output, $file_return);
                 if (intval($file_return) != 0) {
                     return array('location' => 'backup.php', 'status' => 'There was an error (code ' . intval($file_return) . ') while creating a backup of the database structure. Please try again.', 'class' => 'error');
                 }
                 $output_files[] = $backup_file_name;
                 break;
             case 'files':
                 $backup_file_name = 'backup-files-' . $timestamp . '.zip';
                 $backup_file_command = 'cd ' . APP_ROOT . ' && zip -q --compression-method bzip2 -9 -x backups/\\* -r backups/' . $backup_file_name . ' .';
                 exec($backup_file_command, $file_output, $file_return);
                 if (intval($file_return) != 0) {
                     return array('location' => 'backup.php', 'status' => 'There was an error (code ' . intval($file_return) . ') while creating a backup of the files. Please try again.', 'class' => 'error');
                 }
                 $output_files[] = $backup_file_name;
                 break;
             default:
                 break;
         }
     }
     if (count($output_files) < 1) {
         return array('location' => 'backup.php', 'status' => 'Nothing was successfully backed up. Please try again.', 'class' => 'error');
     }
     //create a single backup tarball.
     $backup_file_name = 'backup-' . $timestamp . '.zip';
     $tar_command = 'cd ' . APP_ROOT . '/backups/ && zip -q --compression-method bzip2 ' . $backup_file_name . ' ' . implode(' ', $output_files);
     $cleanup_command = 'cd ' . APP_ROOT . '/backups/ && rm ' . implode(' ', $output_files);
     exec($tar_command, $tar_output, $tar_return);
     if (intval($tar_return) != 0) {
         return array('location' => 'backup.php', 'status' => 'There was an error (code ' . intval($tar_return) . ') while creating a master tarball backup. Please try again.', 'class' => 'error');
     }
     exec($cleanup_command, $cleanup_output, $cleanup_return);
     if (intval($cleanup_return) != 0) {
         return array('location' => 'backup.php', 'status' => 'There was an error (code ' . intval($cleanup_return) . ') while cleaning up the backup directory. Please try again.', 'class' => 'error');
     }
     //insert this backup into the db list.
     $insert_backup = $this->stdQuery("INSERT INTO `backups` (`created_at`, `path`, `user_id`) VALUES ('" . date('Y-m-d H:i:s') . "', " . $this->quoteSmart('backups/' . $backup_file_name) . ", " . intval($user->id) . ")");
     if (!$insert_backup) {
         return array('location' => 'backup.php', 'status' => 'There was an error while logging the backup. Please try again.', 'class' => 'error');
     }
     $insert_id = $this->insert_id;
     //now do what the user has requested with these backup files.
     foreach ($backup['action'] as $action) {
         switch ($action) {
             case 'local':
                 break;
             case 'remote':
                 return array('location' => 'backup.php?action=download&id=' . intval($insert_id));
                 break;
             default:
                 break;
         }
     }
     return array('location' => 'backup.php', 'status' => 'Backup successfully created.', 'class' => 'success');
 }