Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "Base/header.php";
- if(!$loggedIn)
- header("Location:login.php");
- $fields = array("old", "text", "tags", "name", "subject");
- $full = true;
- $errors = [];
- foreach($fields as $f){
- if(!isset($_POST[$f])){
- $full = false;
- }
- }
- if($full){
- $name = $_POST['name'];
- $old = $_POST['old'];
- $subject = $_POST['subject'];
- $content = $_POST['text'];
- $keys = $_POST['tags'];
- if($name == $old)
- $name = "";
- $sql = "SELECT * FROM pages WHERE name='$name'";
- $result = mysqli_query($conn, $sql);
- if ($rrow = mysqli_fetch_assoc($result)) {
- array_push($errors, "<strong>Error:</strong> A page with that name does already exist!");
- }else{
- if($name == "")
- $name = $old;
- $sql = "UPDATE pages SET name='".mysqli_real_escape_string($conn, $name)."', subject='".mysqli_real_escape_string($conn, $subject)."',',content='".mysqli_real_escape_string($conn, $content)."',keywords='".mysqli_real_escape_string($conn, $keys)."' WHERE name='".mysqli_real_escape_string($conn, $old)."'";
- mysqli_query($conn, $sql);
- $sql = "SELECT * FROM pages WHERE name='$name'";
- $result = mysqli_query($conn, $sql);
- $roww = mysqli_fetch_assoc($result);
- $id = $roww['id'];
- header("Location: view.php?i=".$id);
- }
- }
- $exist = true;
- if(isset($_GET['i'])){
- $id = mysqli_real_escape_string($conn, $_GET['i']);
- $sql = "select * FROM `pages` WHERE id=\"".$id."\"";
- $result = mysqli_query($conn, $sql);
- if(mysqli_num_rows($result) == 0){
- $exist = false;
- }else{
- $resRow = mysqli_fetch_assoc($result);
- }
- }
- ?>
- <style>
- .bbedit{
- min-height:100px;
- width:100%;
- }
- .bbsymbs{
- width:100%;
- padding: 2.5px;
- }
- .bb-symbol {
- display: inline-block;
- width: 32px;
- height: 32px;
- padding: 8px;
- color: transparent !important;
- }
- .bb-class{
- background-color: #f5f5f5;
- border-radius: 5px;
- }
- .bb-symbol:hover:active{
- color: transparent !important;
- }
- .bb-img{
- height:16px;
- width: 16px;
- }
- .bb-a{
- display: inline-block;
- height: 32px;
- width: 32px;
- z-index: 4;
- cursor: pointer;
- }
- .bb-a:hover, .bb-active{
- background-color: #e1e1e1;
- border-radius: 4px;
- }
- .bb-group{
- z-index: 3;
- height: 32px;
- background-color: #ebebeb;
- border-radius: 5px;
- display: inline-block;
- width: auto;
- }
- .bb-ifr{
- border:none;
- height: 100%;
- width: 100%;
- }
- .list-group-item{
- padding: 0px;
- margin: 0px;
- }
- .bb-color-option{
- height: 30px;
- width: auto;
- }
- .bb-bold{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -624px;
- }
- .bb-italic{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -384px;
- }
- .bb-underline{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -48px;
- }
- .bb-strikethrough{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -128px;
- }
- .bb-subscript{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -112px;
- }
- .bb-superscript{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -96px;
- }
- .bb-left{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -352px;
- }
- .bb-center{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -592px;
- }
- .bb-right{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -192px;
- }
- .bb-size{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -160px;
- }
- .bb-font{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -464px;
- }
- .bb-color{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -560px;
- }
- .bb-hr{
- background-image: url('Base/icons.png');
- background-repeat: no-repeat;
- background-position: 0 -432px;
- }
- .bg-img-div{
- resize: both;
- overflow: auto;
- height:max-content;
- width:max-content;
- }
- .bb-img{
- height:100%;
- width:100%;
- }
- </style>
- <div class="container">
- <?php
- if(!isset($_GET['i']) || !$exist){
- echo " <div class=\"alert alert-danger alert-dismissable fade in text-center\">
- <a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
- <strong>Error!</strong> ID not found!</div>";}
- ?>
- <div class="page-header">
- <h1>Edit</h1>
- </div>
- <?php
- if(!isset($_GET['i']) || !$exist){
- include "Base/footer.php";
- return;
- }
- ?>
- <div id="errors"></div>
- <form method="POST" class="required" id="createform" name="createform" onsubmit="return validateForm()">
- <div class="form-group">
- <ul class="list-group">
- <li class="list-group-item">
- <div class="bb-class">
- <div class="bbsymbs">
- <div class="bb-group">
- <a class="bb-a" data-bb-value="bold" onclick="h(this)" title="Bold">
- <div class="bb-symbol">
- <div class="bb-img bb-bold"></div>
- </div></a> <a class="bb-a" data-bb-value="italic" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-italic"></div>
- </div></a> <a class="bb-a" data-bb-value="underline" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-underline"></div>
- </div></a> <a class="bb-a" data-bb-value="strikethrough" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-strikethrough"></div>
- </div></a> <a class="bb-a" data-bb-value="subscript" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-subscript"></div>
- </div></a> <a class="bb-a" data-bb-value="superscript" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-superscript"></div>
- </div></a>
- </div>
- <div class="bb-group">
- <a class="bb-a bb-just" data-bb-value="justifyLeft" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-left"></div>
- </div></a> <a class="bb-a bb-just" data-bb-value="justifyCenter" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-center"></div>
- </div></a> <a class="bb-a bb-just" data-bb-value="justifyRight" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-right"></div>
- </div></a>
- </div>
- <div class="bb-group">
- <a class="bb-a" data-bb-value="fontName" id="bb-font-parent" onclick="font(this)" title="Font">
- <div class="bb-symbol">
- <div class="bb-img bb-font"></div>
- </div></a> <a class="bb-a" data-bb-value="fontSize" id="bb-size-parent" onclick="size(this)" title="Bold">
- <div class="bb-symbol">
- <div class="bb-img bb-size"></div>
- </div></a> <a class="bb-a" data-bb-value="foreColor" id="bb-color-parent" onclick="color(this)" title="Color">
- <div class="bb-symbol">
- <div class="bb-img bb-color"></div>
- </div></a>
- </div>
- <div class="bb-group">
- <a class="bb-a" data-bb-value="insertHorizontalRule" onclick="h(this)">
- <div class="bb-symbol">
- <div class="bb-img bb-hr"></div>
- </div></a>
- </div>
- </div>
- </div><iframe class="bb-ifr" id="bb-frame" name="bb-frame" style="resize: vertical;"></iframe>
- </li>
- </ul>
- <label for="ntag" class="required">
- Tags:
- </label>
- <br>
- <ul class="pagination" id="tagsul">
- <li class="remtag">
- <a href="#">Add tags in the box below</a>
- </li>
- <li class="remtag">
- <a href="#">Click a tag to remove it</a>
- </li>
- </ul><br>
- <input class="form-control" id="ntag" maxlength="64" placeholder="Add a tag" style="display: inline; width: 74%;" type="text"> <input class="btn btn-success" onclick="addTag()" style="display: inline;width:24%" type="button" value="Add tag">
- </div><br>
- <label for="name" class="required">
- Name:
- </label>
- <input id="name" class="form-control" maxlength="64" name="name" placeholder="Name" type="text"><br>
- <label for="subject" class="required">
- Subject:
- </label>
- <select id="subject" class="form-control" name="subject"><br>
- <option id="ss" disabled style="display: none;" selected>Select subject</option>
- <option>Literatue</option>
- <option>Geography</option>
- <option>History</option>
- <option>Biology</option>
- <option>Chemistry</option>
- <option>Physics</option>
- <option>Mathmatics</option>
- </select><br>
- <button class="btn btn-default" type="submit">Submit</button>
- <div id="hids"></div>
- <input type="hidden" name="old" value="<?php echo $resRow['name'];?>">
- </form>
- </div>
- <script>
- $("#bg-img-div").addClass("bg-img-div");
- $("#bb-img").addClass("bb-img");
- </script>
- <div id="bb-size" style="background-color: white; border-radius: 4px; border: 1px solid black; padding: 3px; width:100px;">
- <ul class="list-group" style="margin: 0px; cursor: pointer;">
- <li class="list-group-item bb-size-option" data-size="1"><font size="1">1</font></li>
- <li class="list-group-item bb-size-option" data-size="2"><font size="2">2</font></li>
- <li class="list-group-item bb-size-option" data-size="3"><font size="3">3</font></li>
- <li class="list-group-item bb-size-option" data-size="4"><font size="4">4</font></li>
- <li class="list-group-item bb-size-option" data-size="5"><font size="5">5</font></li>
- <li class="list-group-item bb-size-option" data-size="6"><font size="6">6</font></li>
- <li class="list-group-item bb-size-option" data-size="7"><font size="7">7</font></li>
- </ul>
- </div>
- <div id="bb-font" style="background-color: white; border-radius: 4px; border: 1px solid black; padding: 3px; width:100px;">
- <ul class="list-group" style="margin: 0px; cursor: pointer;">
- <li class="list-group-item bb-font-option" data-font="Arial"><font face="Arial">Arial</font></li>
- <li class="list-group-item bb-font-option" data-font="Comic Sans MS"><font face="Comic Sans MS">Comic Sans MS</font></li>
- <li class="list-group-item bb-font-option" data-font="Consolas"><font face="Consolas">Consolas</font></li>
- <li class="list-group-item bb-font-option" data-font="Courier New"><font face="Courier New">Courier New</font></li>
- <li class="list-group-item bb-font-option" data-font="Verdana"><font face="Verdana">Verdana</font></li>
- </ul>
- </div>
- <div id="bb-color" style="background-color: white; border-radius: 4px; border: 1px solid black; padding: 3px; width:100px; cursor: pointer; width: 100px">
- <div class="bb-color-option" data-color="#001f3f" style=""></div>
- <div class="bb-color-option" data-color="#0074D9" style=""></div>
- <div class="bb-color-option" data-color="#39CCCC" style=""></div>
- <div class="bb-color-option" data-color="#3D9970" style=""></div>
- <div class="bb-color-option" data-color="#2ECC40" style=""></div>
- <div class="bb-color-option" data-color="#01FF70" style=""></div>
- <div class="bb-color-option" data-color="#FFDC00" style=""></div>
- <div class="bb-color-option" data-color="#FF851B" style=""></div>
- <div class="bb-color-option" data-color="#FF4136" style=""></div>
- <div class="bb-color-option" data-color="#85144b" style=""></div>
- <div class="bb-color-option" data-color="#F012BE" style=""></div>
- <div class="bb-color-option" data-color="#111111" style=""></div>
- <div class="bb-color-option" data-color="#AAAAAA" style=""></div>
- <div class="bb-color-option" data-color="#FFFFFF" style="border: 1px solid"></div>
- </div>
- <script>
- var iframe = document.getElementById("bb-frame");
- var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- var actives = [];
- var iftxt;
- var tags = [];
- var sizeAct = false;
- var fontAct = false;
- var colorAct = false;
- function error(text, id){
- var e = "<div id=\"" + id + "\" class=\"alert alert-danger alert-dismissable fade text-center\"> <a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>" + text + "</div>";
- document.getElementById("errors").innerHTML+=e;
- window.setTimeout(function () {
- $("#" + id).addClass("in");
- }, 15);
- }
- function validateForm() {
- addTag();
- var taglist = "";
- for (var t in tags) {
- taglist = taglist + tags[t] + ",";
- }
- taglist = taglist.slice(0, -1);
- document.getElementById("hids").innerHTML="";
- document.getElementById("hids").innerHTML += "<input type=\"hidden\" name=\"tags\" value=\"" + taglist + "\">";
- document.getElementById("hids").innerHTML += "<input type=\"hidden\" name=\"text\" value=\"" + escape(iframeDocument.body.innerHTML) + "\">";
- var r = true;
- document.getElementById("errors").innerHTML="";
- var tagsel = document.getElementsByName("tags")[0];
- var text = document.getElementsByName("text")[0];
- var name = document.getElementsByName("name")[0];
- var subject = document.getElementsByName("subject")[0];
- if(text.value==""){
- error("<strong>Error!</strong> Please enter text!", "errtext");
- r = false;
- }
- if(tagsel.value==""){
- error("<strong>Error!</strong> Please enter tags!", "errtags");
- r = false;
- }
- if(name.value==""){
- error("<strong>Error!</strong> Please enter a valid name!", "errname");
- r = false;
- }
- if(subject.value==$("#ss")[0].innerHTML.toLowerCase()){
- error("<strong>Error!</strong> Please enter a valid subject!", "errsubject");
- r = false;
- }
- if(!r){
- window.scrollTo(100,0);
- }
- document.getElementById("hids").innerHTML="";
- if(!r)
- return r;
- document.getElementById("hids").innerHTML += "<input type=\"hidden\" name=\"tags\" value=\"" + taglist + "\">";
- document.getElementById("hids").innerHTML += "<input type=\"hidden\" name=\"text\" value=\"" + escape(iframeDocument.body.innerHTML) + "\">";
- return r;
- }
- function h(d) {
- if (d.classList.contains("bb-just"))
- $(".bb-just").removeClass("bb-active");
- if (d.classList.contains("bb-active")) {
- d.classList.remove("bb-active");
- } else {
- d.classList.add("bb-active");
- }
- /*
- Yes, it works, classes are changed first
- */
- iframeDocument.body.focus();
- }
- function addTag() {
- var tag = $("#ntag").val();
- if (tag == "" || tag == " ")
- return;
- /*
- Tag valid!
- */
- $("#tagsul")[0].innerHTML = "";
- tags.push(tag);
- for (var s in tags) {
- $("#tagsul")[0].innerHTML += "<li class=\"remtag\" data-tag=\"" + tag + "\"><a href=\"#\">" + tags[s] + "<\/a><\/li>";
- }
- $("#ntag").val("");
- $("#ntag").focus();
- $(".remtag").click(function () {
- deleteTag($(this));
- });
- }
- function addTagWT(tag) {
- if (tag == "" || tag == " ")
- return;
- /*
- Tag valid!
- */
- $("#tagsul")[0].innerHTML = "";
- tags.push(tag);
- for (var s in tags) {
- $("#tagsul")[0].innerHTML += "<li class=\"remtag\" data-tag=\"" + tag + "\"><a href=\"#\">" + tags[s] + "<\/a><\/li>";
- }
- $("#ntag").val("");
- $("#ntag").focus();
- $(".remtag").click(function () {
- deleteTag($(this));
- });
- }
- function deleteTag(tagel) {
- tagel.css("display", "none");
- tags.pop(tagel.data("tag"));
- }
- function size(d) {
- h(d);
- if (!sizeAct) {
- $("#bb-size").show();
- $("#bb-size").css('top', $("#bb-size-parent").offset()["top"] + $("#bb-size-parent").height() + 5);
- $("#bb-size").css('left', $("#bb-size-parent").offset()["left"]);
- $("#bb-size").css('position', 'fixed');
- sizeAct = true;
- } else {
- $("#bb-size").hide();
- sizeAct = false;
- }
- }
- function font(d) {
- h(d);
- if (!fontAct) {
- $("#bb-font").show();
- $("#bb-font").css('top', $("#bb-font-parent").offset()["top"] + $("#bb-font-parent").height() + 5);
- $("#bb-font").css('left', $("#bb-color-parent").offset()["left"]);
- $("#bb-font").css('position', 'fixed');
- fontAct = true;
- } else {
- $("#bb-font").hide();
- fontAct = false;
- }
- }
- function color(d) {
- h(d);
- if (!colorAct) {
- $("#bb-color").show();
- $("#bb-color").css('top', $("#bb-color-parent").offset()["top"] + $("#bb-color-parent").height() + 5);
- $("#bb-color").css('left', $("#bb-color-parent").offset()["left"]);
- $("#bb-color").css('position', 'fixed');
- colorAct = true;
- } else {
- $("#bb-color").hide();
- colorAct = false;
- }
- }
- $(document).keypress(function (event) {
- if (event.keyCode == 13 && $("#ntag").is(':focus')) {
- var tag = $("#ntag").val();
- addTag();
- event.preventDefault();
- }
- });
- $(document).ready(function () {
- iframe = document.getElementById("bb-frame");
- iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
- iframeDocument.body.contentEditable = "true";
- $(".bb-font-option").click(function () {
- var d = $("#bb-font-parent")[0];
- font(d);
- iframeDocument.execCommand($("#bb-font-parent").data('bb-value'), false, $(this).data("font"));
- });
- $("option").each(function () {
- $(this)[0].value = $(this)[0].innerHTML.toLocaleLowerCase();
- <?php
- if(isset($resRow['subject'])){
- echo "if(\"".strtolower($resRow['subject'])."\" == $(this)[0].innerHTML.toLocaleLowerCase())
- $(this)[0].selected = \"selected\";";
- }
- ?>
- });
- $(".remtag").click(function () {
- deleteTag($(this));
- });
- <?php
- if(isset($resRow['name'])){
- echo "$(\"#name\")[0].value=\"".$resRow['name']."\";";
- }
- ?>
- <?php
- if(isset($resRow['content'])){
- echo "iframeDocument.body.innerHTML=unescape(\"".html_entity_decode($resRow['content'])."\");";
- }
- ?>
- iframeDocument.addEventListener("keyup", function () {
- $("#bb-frame").contents().find("body").find("img").each(function () {
- if (!$(this).hasClass("bb-img")) {
- $(this).wrap("<div class=\"bb-img-div\" ><\/div>");
- $(this).parent().css("background-color", "white");
- $(this).parent().css("height", $(this).height());
- $(this).parent().css("width", $(this).width());
- $(this).parent().css("resize", "both");
- $(this).parent().css("overflow", "auto");
- $(this).css("height", "100%");
- $(this).css("width", "100%");
- $(this).addClass("bb-img");
- }
- });
- if ($("#bb-frame").height() < $("#bb-frame").height() + 100 + $(this).height())
- $("#bb-frame").height = $("#bb-frame").height() + 100 + $(this).height();
- });
- $("#bb-size").hide();
- $("#bb-font").hide();
- $("#bb-color").hide();
- $(".bb-a").click(function (e) {
- var command = $(this).data('bb-value');
- iframeDocument.execCommand($(this).data('bb-value'), false, null);
- });
- $(".bb-size-option").click(function () {
- var d = $("#bb-size-parent")[0];
- size(d);
- iframeDocument.execCommand($("#bb-size-parent").data('bb-value'), false, $(this).data("size"));
- });
- $(".bb-color-option").each(function () {
- $(this).css("background-color", "" + $(this).data("color"));
- });
- $(".bb-color-option").click(function () {
- var d = $("#bb-color-parent")[0];
- color(d);
- iframeDocument.execCommand($("#bb-color-parent").data('bb-value'), false, $(this).data("color"));
- });
- <?php
- if(isset($resRow['keywords'])){
- $tags = explode(",", $resRow['keywords']);
- foreach ($tags as $t){
- echo "addTagWT(\"".html_entity_decode(urldecode($t))."\");";
- }
- }
- ?>
- });
- </script>
- <?php
- if(!empty($errors)){
- $i = 0;
- foreach ($errors as $e){
- echo "<script>error(\"".$e."\",".$i.");</script>";
- $i++;
- }
- }
- ?>
- <?php
- include "Base/footer.php";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement