예제 #1
0
파일: admin.php 프로젝트: ptitmax/42
        echo "<input type='submit' name='submit' value='delete' > </form>";
    }
    echo "</br>";
    echo "</br>";
    $done = NULL;
    while ($tab2 = get_type_categorie($tab, 'Other', $done)) {
        echo "<form method='post' action='admin.php'>";
        echo "Categorie :";
        echo "<input type='text' name='type' value='" . $tab2[0]['type'] . "'></br>";
        echo "<input type='submit' name='submit' value='delete_categorie' > </form>";
        $done[] = $tab2[0]['type'];
    }
}
if ($_POST['submit'] == 'Create') {
    include "create_content.php";
    create_content($_POST['name'], $_POST['type'], $_POST['med_type'], $_POST['med_value'], $_POST['desc'], $_POST['prix']);
    $_POST['submit_admin'] = 'Admin';
    $_POST['name'] = NULL;
}
if ($_POST['name']) {
    foreach ($tab as $key) {
        if ($_POST['name'] == $key['name']) {
            echo "<form method='post' action='admin.php'>";
            echo "<input type='hidden' name='old_name' value='" . $key['name'] . "'></br>";
            echo "nom : \n" . "<input type='text' name='name' value='" . $key['name'] . "'> </br>";
            echo "<input type='hidden' name='old_type' value='" . $key['type'] . "'></br>";
            echo "Categorie : \n" . "<input type='text' name='type' value='" . $key['type'] . "'></br>";
            echo "type de media (vid/img) : \n" . "<input type='text' name='med_type' value='" . $key['med_type'] . "'></br>";
            echo "url / path : \n" . "<input type='text' name='med_value' value='" . $key['med_value'] . "'></br>";
            echo "description : " . substr($key['description'], 0, 25) . "..." . "</br>";
            echo "<input type='hidden' name='old_desc' value='" . $key['description'] . "''> </br>";
예제 #2
0
<?php

session_start();
// Aloitetaan istunto.
require_once 'kokonaisuudet/asetukset/tietokantayhteys.php';
require_once 'kokonaisuudet/yhteiset/php_yhteismetodit.php';
load_files("home");
$head = create_head();
$nav = create_nav();
$footer = create_footer();
$content = create_content();
$content_container = Html::luo_div($content, array(Attr::classs("container text-center")));
$html = Html::luo_body($head . $nav . $content_container . $footer, array());
$doc = Html::luo_html($html, array());
echo $doc;
//===================== Funktiot ===========================================
/**
 * Creates the html for head element with addresses for Bootstrap.
 * @return type
 */
function create_head()
{
    $text = Html::luo_head(Html::luo_title(Tekstit::$home_title, array()) . Html::luo_link_to_stylesheet("http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css") . Html::luo_link_to_stylesheet("css/etusivutyylit.css") . Html::luo_script_to_js("https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js") . Html::luo_script_to_js("http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js") . Html::luo_meta(array(Attr::charset("utf-8"))) . Html::luo_meta(array(Attr::name("viewport"), Attr::content("width=device-width, initial-scale=1"))), array());
    return $text;
}
/**
 * Creates the html for the main content.
 */
function create_content()
{
    $content = Html::luo_div(Html::luo_div(Html::luo_div(Html::luo_otsikko(Tekstit::$home_heading_main, array(Attr::classs("")), 1) . Html::luo_p(Tekstit::$home_wellcome_text, array()), array(Attr::classs("col-sm-12"))), array(Attr::classs("row"))) . Html::luo_div(Html::luo_div(Html::luo_div(Html::luo_otsikko(ucwords(Tekstit::$oppiaine_nimi_MA), array(Attr::classs("")), 3) . create_links_of_subject(Oppiaineet::$MA), array(Attr::classs("well"))), array(Attr::classs("col-sm-4"))) . Html::luo_div(Html::luo_div(Html::luo_otsikko(ucwords(Tekstit::$oppiaine_nimi_TT), array(Attr::classs("")), 3) . create_links_of_subject(Oppiaineet::$TT), array(Attr::classs("well"))), array(Attr::classs("col-sm-4"))) . Html::luo_div(Html::luo_div(Html::luo_otsikko(ucwords(Tekstit::$oppiaine_nimi_FY), array(Attr::classs("")), 3) . create_links_of_subject(Oppiaineet::$FY), array(Attr::classs("well"))), array(Attr::classs("col-sm-4"))), array(Attr::classs("row"))), array(Attr::classs("container text-center")));
/**
 * Summary of update_post
 * @param mixed $post_data 
 * @param mixed $file_data 
 * @param mixed $draft 
 * @return bool|string
 */
function update_post($post_data, $file_data = '', $draft = null)
{
    $found = true;
    $errors = '';
    $updated_post = create_post_array($post_data);
    $i = 0;
    //Check if the post exist to proceed
    if (post_exist((int) $post_data['id'])) {
        $posts_file = get_json_content(CONTENTPATH . 'content.json');
        $posts =& $posts_file['posts'];
        // Update database and update image if submitted
        while ($i < count($posts)) {
            if ($posts[$i]['id'] === (int) $post_data['id']) {
                //Avoid updating .content file and url
                $updated_post['content'] = $posts[$i]['content'];
                $updated_post['url'] = $posts[$i]['url'];
                //Set extra settings
                if ($draft === null) {
                    $updated_post['status'] = $posts[$i]['status'];
                } else {
                    $updated_post['status'] = $draft === true ? 'DRAFT' : 'ACTIVE';
                }
                //Update image
                if (!empty($file_data)) {
                    $uploaded = upload_img($file_data, 5000000);
                    $updated_post['image'] = $uploaded['response'];
                    if (!$uploaded['success']) {
                        $errors .= "Your header image was not updated.\r\n";
                    }
                } else {
                    $updated_post['image'] = $posts[$i]['image'];
                }
                //Place new post in place of old one
                $posts[$i] = $updated_post;
                break;
            }
            $i++;
        }
        //If posts was found and database updated continue with .content and
        //saving the database
        if ($found === true) {
            if (create_content($post_data['url'] . '.content', $post_data['content'])) {
                if (!write_to_json(CONTENTPATH . 'content.json', $posts_file)) {
                    $errors .= "Your post could not be saved please try again\r\n";
                }
                $errors .= "contentError:Your post could not be saved please try again\r\n";
            }
        }
    } else {
        $errors .= "Post could not be found\r\n";
    }
    return empty($errors) ? true : $errors;
}