Location: PHPKode > projects > PhpChangeLog > phpchangelog-0.6/functions/functions.inc.php
<?php

/**
 * phpChangeLog Functions
 *
 * This script holds all functions used in phpChangeLog
 */

    # Drop a database
    function drop_db($db) {
        $query = "SELECT * FROM db WHERE id='$db'";
        $result = mysql_query($query) or die (mysql_error());
        $affected_rows = mysql_num_rows($result);
        if ($affected_rows < 1) {
            die ('error making query');
        } else {
            $record = mysql_fetch_object($result);
            mysql_query("DROP TABLE ".$record->db."_changelog") or die (mysql_error());
            mysql_query("DROP TABLE ".$record->db."_projects") or die (mysql_error());
            mysql_query("DROP TABLE ".$record->db."_maintainers") or die (mysql_error());
            mysql_query("DELETE FROM db WHERE db='$record->db'") or die (mysql_error());
        }
    }

    # Drop an entry in your changelog
   ## function drop_entry()
     ## mysql_query("DELETE " from 'changelog' WHERE 'id' ='$record->id' LIMIT 1) or die (msql_error());


    # Create a new database for phpChangeLog
    function create_new_db($dbname) {
        addslashes($dbname);
        $query = "SELECT * FROM db WHERE db='$dbname'";
        $result = mysql_query($query) or die('error making query');
        $affected_rows = mysql_num_rows($result);
        if ($affected_rows > 0) {
            echo "    Database already exists\n";
        } else {

       mysql_query("INSERT INTO db (db) VALUES ('$dbname')") or die (mysql_error());
       mysql_query("CREATE TABLE ".$dbname."_changelog (
                        id int(11) NOT NULL auto_increment,
                        project_id int(11) NOT NULL default '0',
                        maintainer_id int(11) NOT NULL default '0',
                        date varchar(20) NOT NULL default '0',
                        comment text NOT NULL,
                        UNIQUE KEY id (id)
                        ) TYPE=MyISAM;") or die (mysql_error());

        mysql_query("CREATE TABLE ".$dbname."_maintainers (
                  id int(11) NOT NULL auto_increment,
                  maintainer varchar(255) NOT NULL default '',
                  password varchar(250) NOT NULL default '',
                  UNIQUE KEY id (id)
                ) TYPE=MyISAM;") or die (mysql_error());

        mysql_query("INSERT INTO ".$dbname."_maintainers VALUES (1,'admin', MD5('admin'))") or die (mysql_error());

        mysql_query("CREATE TABLE ".$dbname."_projects (
                  id int(11) NOT NULL auto_increment,
                  project varchar(255) NOT NULL default '',
                  UNIQUE KEY id (id)
                ) TYPE=MyISAM;") or die (mysql_error());
        }
    }

    # Show a form for addition of maintainers or projects
    function show_add_type($type,$thisfile) {
        echo "   <b>Add a new $type</b>\n";
        echo "   <form method=\"post\" action=\"$thisfile\">\n";
        echo "    $type <input type=\"text\" name=\"$type\" />\n";
        if ($type == "maintainer") {
            echo "    Password <input type=\"password\" name=\"password\" />\n";
        }
        echo "    <input type=\"submit\" value=\"add\" />\n";
        echo "    <input type=\"hidden\" name=\"add_type\" value=\"TRUE\" />\n";
        echo "   </form>\n";
    }

    # Add the item to the database (maintainers or projects)
    function add_type_db($type,$table,$value,$password) {
        addslashes($type);
        addslashes($table);
        addslashes($value);
        $tbl = $_SESSION['database'] ."_$table";
        if ($type == "project") {
            mysql_query("INSERT INTO $tbl ($type) VALUES ('$value')")
            || die ("Cannot add $type to the database");
        } elseif ($type == "maintainer") {
            addslashes($password);
            mysql_query("INSERT INTO $tbl ($type, password) VALUES ('$value', MD5('$password'))")
            || die ("Cannot add $type to the database");
        }
    }

    # Show a header with the selected project
    function show_selected_project($id) {
        $tbl = $_SESSION['database'] ."_projects";
        $sql_get = mysql_query("SELECT * FROM $tbl WHERE id = '$id' ORDER BY project");
        $record = mysql_fetch_object($sql_get);
        echo "    Selected project : $record->project<br /> \n";
        echo "    User logged in   :" .$_SESSION['maintainer'];
        echo "    <a class=\"link\" href=\"./index.php?logout=TRUE\">[logout]</a>\n";
    }

    # Show all items in the mainmenu
    function show_items($type,$thisfile) {
        if ($type == "projects") {
            $tbl = $_SESSION['database'] ."_projects";
            $sql_get = mysql_query("SELECT * FROM $tbl ORDER BY project");
            print "   <b>Projects</b><br />";
            while ($record = mysql_fetch_object($sql_get)) {
                echo "   <a class=\"link\" href=\"$thisfile?remove_project=$record->id\" ";
                echo " onclick=\"return confirm('Remove project $record->project?')\">\n";
                echo "   <img src=\"img/remove.gif\" border=\"0\" alt=\"Remove $record->project\" /></a>\n";
                echo "   <a class=\"link\" href=\"$thisfile?render=getchlog&amp;id=$record->id&amp;";
                echo "project=$record->id\">$record->project</a>\n";
                echo "   <br /> \n";
            }
            echo "   <i>&nbsp;&nbsp;&nbsp;<a class=\"link\" href=\""; print $thisfile;
            echo "?render=addproject\">add</a></i>\n";
            echo "   <br /><br /> \n";
        } elseif ($type == "maintainers") {
            $tbl = $_SESSION['database'] ."_maintainers";
            $sql_get = mysql_query("SELECT * FROM $tbl ORDER BY maintainer");
            echo "   <b>Maintainers</b><br />\n";

            while ($record = mysql_fetch_object($sql_get)) {
                echo "   <a class=\"link\" href=\"$thisfile?remove_maintainer=$record->id \"";
                echo "onclick=\"return confirm('Remove maintainer $record->maintainer?')\">\n";
                echo "   <img src=\"img/remove.gif\" border=\"0\" alt=\"Remove $record->maintainer\" /></a>\n";
		echo "   <a class=\"link\" href=\"$thisfile?edit_maintainer=$record->id\">";
		echo "   <img src=\"img/edit.gif\" border=\"0\" alt=\"Edit $record->maintainer\" /></a>\n";
                echo "   <a class=\"link\" href=\"$thisfile?render=getprmnt&amp;id=$record->id\">";
                echo "$record->maintainer</a>\n";
                echo "   <br /> \n";
            }

            echo "   <i>&nbsp;&nbsp;&nbsp;<a class=\"link\" href=\""; print $thisfile;
            echo "?render=addmaintainer\">add</a></i>\n";
            echo "   <br />\n";
        }
    }

# Function to remove html code from a variable
function html_remove($strhtml){
    $html4 = array("<A ", "</A", "<ABBR", "</ABBR", "<ACRONYM", "</ACRONYM", "<ADDRESS", "</ADDRESS", "<APPLET", "</APPLET",
    "<AREA", "</AREA", "<B", "</B", "<BASE", "</BASE", "<BASEFONT", "<BDO ", "<BIG", "</BIG",
    "<BLOCKQUOTE", "</BLOCKQUOTE", "<BODY", "</BODY", "<BR", "<BUTTON", "</BUTTON", "<CAPTION", "</CAPTION",
    "<CENTER", "</CENTER", "<CITE", "</CITE", "<CODE", "</CODE", "<COL", "<COLGROUP", "</COLGROUP", "<DD",
    "<DEL", "</DEL", "<DFN", "</DFN", "<DIR", "</DIR", "<DIV ", "</DIV", "<DL", "</DL", "<DT", "<EM", "</EM",
    "<FIELDSET", "</FIELDSET", "<LEGEND", "</LEGEND", "<FONT", "</FONT", "<FORM", "</FORM", "<FRAME",
    "<FRAMESET", "</FRAMESET", "<H", "</H", "<HEAD", "</HEAD", "<HR", "<HTML", "</HTML", "<I", "</I",
    "<IFRAME", "</IFRAME", "<IMG", "<INPUT", "<INS", "</INS", "<ISINDEX", "<KBD", "</KBD", "<LABEL",
    "</LABEL", "<LEGEND", "</LEGEND", "<LI", "</LI", "<LINK ", "<MAP ", "</MAP", "<MENU", "</MENU", "<META",
    "<NOFRAMES", "</NOFRAMES", "<NOSCRIPT", "</NOSCRIPT", "<OBJECT", "</OBJECT", "<OL", "</OL", "<OPTGROUP",
    "</OPTGROUP", "<OPTION", "</OPTION", "<P", "</P", "<PARAM", "<PRE", "</PRE", "<Q", "</Q", "<S", "</S",
    "<SAMP", "</SAMP", "<SCRIPT", "</SCRIPT", "<SELECT", "</SELECT", "<SMALL", "</SMALL", "<SPAN", "</SPAN",
    "<STRIKE", "</STRIKE", "<STRONG", "</STRONG", "<STYLE", "</STYLE", "<SUB", "</SUB", "<SUP", "</SUP",
    "<TABLE", "</TABLE", "<TR", "</TR", "<TD", "</TD", "<TH", "</TH", "<TBODY", "</TBODY", "<TEXTAREA",
    "</TEXTAREA", "<TFOOT", "</TFOOT", "<THEAD", "</THEAD", "<TITLE", "</TITLE", "<TT", "</TT", "<U", "</U",
    "<UL", "</UL", "<VAR", "</VAR", "<XMP", "</XMP");

    $tmpArray = explode("<", $strhtml);
    $output = $tmpArray[0];
    for($i=1;$i<count($tmpArray);$i++){
             $strtmp = "<".$tmpArray[$i];
             for($x=0;$x<count($html4);$x++){
                     if(substr(strtoupper($strtmp), 0, strlen($html4[$x])) != $html4[$x]){
                             continue;
                     }else{
                             $start = strpos($strtmp, ">");
                             $strtmp = substr($strtmp, $start + 1, strlen($strtmp)-$start);
                             break;
                     }
             }
             $output .= $strtmp;
    }
    return $output;
}

?>
Return current item: PhpChangeLog