I really need your help fixing this code.

potoba

Senior member
Oct 17, 2006
738
0
76
I am certainly not a programmer, but there is a problem with my department website and I have been doing all my best trying to fix it. I haven't got any luck so far. :( Everything works fine, except for the "add account" function. When you hit that button, it only says "loading" and nothing happens. I am not sure if it's a quick fix or not, but i've spent so much time on it that I just got sick just by looking at it. Please help if you could. Thank you in advance.

<?php
define("System", true);
include_once '../include/function.inc.php';
include_once '../include/template.inc.php';
global $configs;
$fnc = new BTMainFunction();
if($fnc->getSession("UserRole")!="Administrator"){
header("Location: login.php?accman.php");
exit;
}

$tpl = new template($configs->adminThemePath."/".$configs->adminDefaultTheme);
$tpl->loadTheme("index.html");
$tpl->addValue("{TITLE}", "BT's Portal - Administrator");
$tpl->addValue("{HEADER}", "Administrator Panel");
$tpl->addValue("{SUB_HEADER}", "<a href=\"admin.php\">Control center</a> &gt;&gt; Account Manager");
$tpl->addValue("{SEARCH_FORM}", "Hello <b>{$fnc->getSession("CurrUsername")}</b>. <a href=\"logout.php\">Log out</a>");
$tpl->appendValue("{SEARCH_FORM}", "<br><a href=\"admin.php\">Exit to main menu</a>");
$tpl->addValue("{HEAD}", <<<EOT
<script type="text/javascript" src="../include/highslide/highslide-with-html.js"></script>
<link rel="stylesheet" type="text/css" href="../include/highslide/highslide.css" />
EOT
);
$tpl->addValueFromFile("{DESCRIPTION}", "description.tpl", <<<EOT
<div class="button" onclick="showHSCreate(this)" title="Add account"><img src="{$configs->adminThemePath}/{$configs->adminDefaultTheme}/images/add.gif" height="32" alt="Add account"><br>Add account</div><br><br>
EOT
);

$script=<<<EOT
hs.graphicsDir = '../include/highslide/graphics/';
hs.outlineType = 'rounded-white';
hs.showCredits = false;
hs.wrapperClassName = 'draggable-header';
var isaccexist = false;
var cnt = 0;
var cntrequest = 0;

function getxmlHttp(){
try{
// Firefox, Opera 8.0+, Safari
return new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Your browser does not support AJAX!\\n You cannot complete the test");
return null;
}
}
}
}

function ajaxRequest(data)
{
var xmlHttp = getxmlHttp();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
var response = xmlHttp.responseText;
if(response.indexOf('refresh') != -1)
window.location.reload();
else
alert(response);
}
};
xmlHttp.open("GET","ajax.php?" + data,true);
xmlHttp.send(null);
}

function ajaxCheckAcc(what)
{
var xmlHttp = getxmlHttp();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if(xmlHttp.responseText.indexOf('OK')!=-1){
document.getElementById('accmess').innerHTML = "<br><font color=\\"green\\">This username is available</font>";
isaccexist = false;
}
else{
document.getElementById('accmess').innerHTML = "<br><font color=\\"red\\">This username has been used</font>";
isaccexist=true;
}
}
};
xmlHttp.open("GET","ajax.php?action=checkaccount&uname=" + encodeURIComponent(what.value),true);
xmlHttp.send(null);
}

function showHSCreate(sender){
isaccexist = false;
document.getElementById('passmess').innerHTML = "";
document.getElementById('btnaction').value="Create";
document.getElementById('accid').innerHTML = "NewID";
return hs.htmlExpand(sender, {contentId: 'menuedit',headingText: '.......................Create account.....................' });
}

function showHSEditor(sender, accid){
isaccexist = false;
document.getElementById('passmess').innerHTML = "<br>If you don't wanna change<br> password leave it blank";
document.getElementById('btnaction').value="Edit";
if(document.getElementById('u' + accid + 'name')){
document.getElementById('accuname').value = document.getElementById('u' + accid + 'name').innerHTML;
}
if(document.getElementById('u' + accid + 'role')){
document.getElementById('accroleid').value = document.getElementById('u' + accid + 'role').value;
}
if(document.getElementById('u' + accid + 'fname')){
document.getElementById('accfname').value = document.getElementById('u' + accid + 'fname').innerHTML;
}
if(document.getElementById('u' + accid + 'email')){
document.getElementById('accemail').value = document.getElementById('u' + accid + 'email').innerHTML;
}
document.getElementById('accid').innerHTML = accid;
return hs.htmlExpand(sender, {contentId: 'menuedit',headingText: '........................Edit account......................' });
}

function deleteaccount(sender, accid){
if(document.getElementById('u' + accid + 'name')){
if(confirm("You are going to delete account: '" + document.getElementById('u' + accid + 'name').innerHTML + "' Are you sure?")){
if(accid==1)
return alert('You cannot delete this admin account');
ajaxRequest("action=deleteaccount&accid=" + accid);
}
}
}

function HSE_Close(action){
if(action=="Create"){
var accuname = document.getElementById('accuname').value;
var accroleid = document.getElementById('accroleid').value;
var accpass = document.getElementById('accpass').value;
var accfname = document.getElementById('accfname').value;
var accemail = document.getElementById('accemail').value;
if(accuname==""){
alert('Username cannot be blank');
document.getElementById('accuname').select();
return false;
}
if(isaccexist){
alert('The account you enter has been used. Please enter another');
document.getElementById('accuname').select();
return false;
}
if(accpass==""){
alert('Password cannot be blank');
document.getElementById('accpass').select();
return false;
}
if(accemail!=""){
if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(accemail)==false){
alert("Invalid email address");
document.getElementById('accemail').select();
return false;
}
}
ajaxRequest("action=createaccount&accuname=" + encodeURIComponent(accuname) +
"&accroleid=" + encodeURIComponent(accroleid) +
"&accpass=" + encodeURIComponent(accpass) +
"&accfname=" + encodeURIComponent(accfname) +
"&accemail=" + encodeURIComponent(accemail));
}
if(action=="Edit"){
var accid = document.getElementById('accid').innerHTML;
var accuname = document.getElementById('accuname').value;
var accroleid = document.getElementById('accroleid').value;
var accpass = document.getElementById('accpass').value;
var accfname = document.getElementById('accfname').value;
var accemail = document.getElementById('accemail').value;
if(accuname==""){
alert('Username cannot be blank');
document.getElementById('accuname').select();
return false;
}
if(isaccexist){
alert('The account you enter has been used. Please enter another');
document.getElementById('accuname').select();
return false;
}
if(accemail!=""){
if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(accemail)==false){
alert("Invalid email address");
document.getElementById('accemail').select();
return false;
}
}
if(accid==1 && accroleid!=1){
alert("This is primary admin account. You cannot change role");
document.getElementById('accroleid').value = 1;
return;
}
ajaxRequest("action=editaccount&accid=" + encodeURIComponent(accid) +
"&accuname=" + encodeURIComponent(accuname) +
"&accroleid=" + encodeURIComponent(accroleid) +
"&accpass=" + encodeURIComponent(accpass) +
"&accfname=" + encodeURIComponent(accfname) +
"&accemail=" + encodeURIComponent(accemail));
}
hs.close();
if(action=="none") window.location.reload();
}


function selectAll(){
var x = document.getElementsByName("checkboxes");
if(x && x.length>0){
for(i=0;i<x.length;i++){
if(x.checked)
x.checked = false;
else
x.checked = true;
}
}
}

function deleteall()
{
var x = document.getElementsByName("checkboxes");
var acc="";
cnt = 0;
if(x && x.length>0){
for(i=0;i<x.length;i++){
if(x.checked){
if(document.getElementById('u' + x.value + 'name'))
acc += "'" + document.getElementById('u' + x.value + 'name').innerHTML + "' ";
}
}
if(acc!="" && prompt("To confirm delete please type 'YeS' (case sensitive):" + acc,"NO")=="YeS"){
document.getElementById('ajaxoutput').innerHTML = "Result:<br>";
for(i=0;i<x.length;i++){
if(x.checked){
cntrequest++;
massAjax("action=deleteaccount&accid=" + x.value,document.getElementById('u' + x.value + 'name').innerHTML);
}
}
}
}
}

function masschangerole()
{
var x = document.getElementsByName("checkboxes");
var acc="";
cnt = 0;
if(x && x.length>0){
for(i=0;i<x.length;i++){
if(x.checked){
if(document.getElementById('u' + x.value + 'name'))
acc += "'" + document.getElementById('u' + x.value + 'name').innerHTML + "' ";
}
}
if(acc!="" && prompt("To confirm change role please type 'YeS' (case sensitive):" + acc,"NO")=="YeS"){
document.getElementById('ajaxoutput').innerHTML = "Result:<br>";
for(i=0;i<x.length;i++){
if(x.checked){
cntrequest++;
massAjax("action=changeaccrole&accid=" + x.value + "&roleid=" + document.getElementById('massroleid').value,document.getElementById('u' + x.value + 'name').innerHTML);
}
}
}
}
}

function massAjax(data,text){
var xmlHttp = getxmlHttp();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
cnt++;
var pos = xmlHttp.responseText.indexOf("refresh");
if(pos>-1 && pos < 10)
document.getElementById('ajaxoutput').innerHTML += "Account " + text + " successfully!<br>";
else
document.getElementById('ajaxoutput').innerHTML += "Account " + text + " failed! " + xmlHttp.responseText + "<br>";
if(cnt>=cntrequest)
document.getElementById('ajaxoutput').innerHTML += "Click <a href=\\"javascript:window.location.reload()\\">here</a> to reload";
}
};
xmlHttp.open("GET","ajax.php?" + data,true);
xmlHttp.send(null);
}


EOT;

$tpl->addValue("{SCRIPT}", $script);
$rolelist = $fnc->listAccountRole();
$content=<<<EOT
<div class="highslide-html-content" id="menuedit">
<br>
<table>
<tr>
<td>Acc ID</td><td id="accid"></td>
</tr>
<tr>
<td>Username*<br><i>Max length:25 characters</i></td><td><input type="text" id="accuname" size="26" maxlength="25" onchange="ajaxCheckAcc(this);"><span id="accmess"><span></td>
</tr>
<tr>
<td>Role*</td>
<td>
<select id="accroleid" style="width:100%">
$rolelist
</select>
</td>
</tr>
<tr>
<td>Password*<br><i>Maxlength:50 characters.</i></td><td><input type="text" id="accpass" size="26" maxlength="50"><span id="passmess"><span></td>
</tr>
<tr>
<td>Fullname*</td><td><input type="text" id="accfname" size="26" maxlength="50"></td>
</tr>
<tr>
<td>Email</td><td><input type="text" id="accemail" size="26" maxlength="100"></td>
</tr>
<tr>
<td></td>
<td>
<input type="button" value="" id="btnaction" onclick="HSE_Close(this.value);">
<input type="button" value="Close" id="btnClose" onclick="HSE_Close('none');">
</td>
</tr>
</table>
(*) field are require.
<br><br>&nbsp;
</div>
EOT;



$page = "1";
$uname = "";
if(isset($_GET['page'])){
$page = $_GET['page'];
}
if(isset($_GET['uname'])){
$uname = $_GET['uname'];
}
$content .= "<center>Search username<input type=\"text\" id=\"uname\" value=\"$uname\"><input type=\"button\" value=\"Search\" onclick=\"window.location.href='?uname=' + encodeURIComponent(document.getElementById('uname').value)\"></center>";
$content .= $fnc->listAccount($page,$uname);



$tpl->addValue("{CONTENT}", $content);
echo $tpl->compileTheme();
?>
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
Please use php blocks for your code. It will make it MUCH more readable for the rest of us.

[php]code goes here[/php]
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
PHP:
<?php
    define("System", true);
    include_once '../include/function.inc.php';
    include_once '../include/template.inc.php';
    global $configs;
    $fnc = new BTMainFunction();
    if($fnc->getSession("UserRole")!="Administrator"){
        header("Location: login.php?accman.php");
        exit;
    }

    $tpl = new template($configs->adminThemePath."/".$configs->adminDefaultTheme);
    $tpl->loadTheme("index.html");
    $tpl->addValue("{TITLE}", "BT's Portal - Administrator");
    $tpl->addValue("{HEADER}", "Administrator Panel");
    $tpl->addValue("{SUB_HEADER}", "<a href=\"admin.php\">Control center</a> &gt;&gt; Account Manager");
    $tpl->addValue("{SEARCH_FORM}", "Hello <b>{$fnc->getSession("CurrUsername")}</b>. <a href=\"logout.php\">Log out</a>");
    $tpl->appendValue("{SEARCH_FORM}", "<br><a href=\"admin.php\">Exit to main menu</a>");
    $tpl->addValue("{HEAD}", <<<EOT
            <script type="text/javascript" src="../include/highslide/highslide-with-html.js"></script>
            <link rel="stylesheet" type="text/css" href="../include/highslide/highslide.css" />
EOT
    );
    $tpl->addValueFromFile("{DESCRIPTION}", "description.tpl", <<<EOT
            <div class="button" onclick="showHSCreate(this)" title="Add account"><img src="{$configs->adminThemePath}/{$configs->adminDefaultTheme}/images/add.gif" height="32" alt="Add account"><br>Add account</div><br><br>
EOT
    );

    $script=<<<EOT
            hs.graphicsDir = '../include/highslide/graphics/';
            hs.outlineType = 'rounded-white';
            hs.showCredits = false;
            hs.wrapperClassName = 'draggable-header';
            var isaccexist = false;
            var cnt = 0;
            var cntrequest = 0;

            function getxmlHttp(){
                try{
                    // Firefox, Opera 8.0+, Safari
                    return new XMLHttpRequest();
                }
                catch (e){
                    // Internet Explorer
                    try    {
                        return new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e){
                        try    {
                            return new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e){
                            alert("Your browser does not support AJAX!\\n You cannot complete the test");
                            return null;
                        }
                    }
                }
            }

            function ajaxRequest(data)
            {
                var xmlHttp = getxmlHttp();
                xmlHttp.onreadystatechange=function(){
                    if(xmlHttp.readyState==4){
                        var response = xmlHttp.responseText;
                        if(response.indexOf('refresh') != -1)
                            window.location.reload();
                        else
                            alert(response);
                    }
                };
                xmlHttp.open("GET","ajax.php?" + data,true);
                xmlHttp.send(null);
            }

            function ajaxCheckAcc(what)
            {
                var xmlHttp = getxmlHttp();
                xmlHttp.onreadystatechange=function(){
                    if(xmlHttp.readyState==4){
                        if(xmlHttp.responseText.indexOf('OK')!=-1){
                            document.getElementById('accmess').innerHTML = "<br><font color=\\"green\\">This username is available</font>";
                            isaccexist = false;
                            }
                        else{
                            document.getElementById('accmess').innerHTML = "<br><font color=\\"red\\">This username has been used</font>";
                            isaccexist=true;
                        }
                    }
                };
                xmlHttp.open("GET","ajax.php?action=checkaccount&uname=" + encodeURIComponent(what.value),true);
                xmlHttp.send(null);
            }

            function showHSCreate(sender){
                isaccexist = false;
                document.getElementById('passmess').innerHTML = "";
                document.getElementById('btnaction').value="Create";
                document.getElementById('accid').innerHTML = "NewID";
                return hs.htmlExpand(sender, {contentId: 'menuedit',headingText: '.......................Create account.....................' });
            }

            function showHSEditor(sender, accid){
                isaccexist = false;
                document.getElementById('passmess').innerHTML = "<br>If you don't wanna change<br> password leave it blank";
                document.getElementById('btnaction').value="Edit";
                if(document.getElementById('u' + accid + 'name')){
                    document.getElementById('accuname').value = document.getElementById('u' + accid + 'name').innerHTML;
                }
                if(document.getElementById('u' + accid + 'role')){
                    document.getElementById('accroleid').value = document.getElementById('u' + accid + 'role').value;
                }
                if(document.getElementById('u' + accid + 'fname')){
                    document.getElementById('accfname').value = document.getElementById('u' + accid + 'fname').innerHTML;
                }
                if(document.getElementById('u' + accid + 'email')){
                    document.getElementById('accemail').value = document.getElementById('u' + accid + 'email').innerHTML;
                }
                document.getElementById('accid').innerHTML = accid;
                return hs.htmlExpand(sender, {contentId: 'menuedit',headingText: '........................Edit account......................' });
            }

            function deleteaccount(sender, accid){
                if(document.getElementById('u' + accid + 'name')){
                    if(confirm("You are going to delete account: '" + document.getElementById('u' + accid + 'name').innerHTML + "' Are you sure?")){
                        if(accid==1)
                            return alert('You cannot delete this admin account');
                        ajaxRequest("action=deleteaccount&accid=" + accid);
                    }
                }
            }

            function HSE_Close(action){
                if(action=="Create"){
                    var accuname = document.getElementById('accuname').value;
                    var accroleid = document.getElementById('accroleid').value;
                    var accpass = document.getElementById('accpass').value;
                    var accfname = document.getElementById('accfname').value;
                    var accemail = document.getElementById('accemail').value;
                    if(accuname==""){
                        alert('Username cannot be blank');
                        document.getElementById('accuname').select();
                        return false;
                    }
                    if(isaccexist){
                        alert('The account you enter has been used. Please enter another');
                        document.getElementById('accuname').select();
                        return false;
                    }
                    if(accpass==""){
                        alert('Password cannot be blank');
                        document.getElementById('accpass').select();
                        return false;
                    }
                    if(accemail!=""){
                        if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(accemail)==false){
                            alert("Invalid email address");
                            document.getElementById('accemail').select();
                            return false;
                        }
                    }
                    ajaxRequest("action=createaccount&accuname=" + encodeURIComponent(accuname) +
                                "&accroleid=" + encodeURIComponent(accroleid) +
                                "&accpass=" + encodeURIComponent(accpass) +
                                "&accfname=" + encodeURIComponent(accfname) +
                                "&accemail=" + encodeURIComponent(accemail));
                }
                if(action=="Edit"){
                    var accid = document.getElementById('accid').innerHTML;
                    var accuname = document.getElementById('accuname').value;
                    var accroleid = document.getElementById('accroleid').value;
                    var accpass = document.getElementById('accpass').value;
                    var accfname = document.getElementById('accfname').value;
                    var accemail = document.getElementById('accemail').value;
                    if(accuname==""){
                        alert('Username cannot be blank');
                        document.getElementById('accuname').select();
                        return false;
                    }
                    if(isaccexist){
                        alert('The account you enter has been used. Please enter another');
                        document.getElementById('accuname').select();
                        return false;
                    }
                    if(accemail!=""){
                        if(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(accemail)==false){
                            alert("Invalid email address");
                            document.getElementById('accemail').select();
                            return false;
                        }
                    }
                    if(accid==1 && accroleid!=1){
                        alert("This is primary admin account. You cannot change role");
                        document.getElementById('accroleid').value = 1;
                        return;
                    }
                    ajaxRequest("action=editaccount&accid=" + encodeURIComponent(accid) +
                                "&accuname=" + encodeURIComponent(accuname) +
                                "&accroleid=" + encodeURIComponent(accroleid) +
                                "&accpass=" + encodeURIComponent(accpass) +
                                "&accfname=" + encodeURIComponent(accfname) +
                                "&accemail=" + encodeURIComponent(accemail));
                }
                hs.close();
                if(action=="none") window.location.reload();
            }


            function selectAll(){
                var x = document.getElementsByName("checkboxes");
                if(x && x.length>0){
                    for(i=0;i<x.length;i++){
                        if(x[i].checked)
                            x[i].checked = false;
                        else
                            x[i].checked = true;
                    }
                }
            }

            function deleteall()
            {
                var x = document.getElementsByName("checkboxes");
                var acc="";
                cnt = 0;
                if(x && x.length>0){
                    for(i=0;i<x.length;i++){
                        if(x[i].checked){
                            if(document.getElementById('u' + x[i].value + 'name'))
                                acc += "'" + document.getElementById('u' + x[i].value + 'name').innerHTML + "' ";
                        }
                    }
                    if(acc!="" && prompt("To confirm delete please type 'YeS' (case sensitive):" + acc,"NO")=="YeS"){
                        document.getElementById('ajaxoutput').innerHTML = "Result:<br>";
                        for(i=0;i<x.length;i++){
                            if(x[i].checked){
                                cntrequest++;
                                massAjax("action=deleteaccount&accid=" + x[i].value,document.getElementById('u' + x[i].value + 'name').innerHTML);
                            }
                        }
                    }
                }
            }

            function masschangerole()
            {
                var x = document.getElementsByName("checkboxes");
                var acc="";
                cnt = 0;
                if(x && x.length>0){
                    for(i=0;i<x.length;i++){
                        if(x[i].checked){
                            if(document.getElementById('u' + x[i].value + 'name'))
                                acc += "'" + document.getElementById('u' + x[i].value + 'name').innerHTML + "' ";
                        }
                    }
                    if(acc!="" && prompt("To confirm change role please type 'YeS' (case sensitive):" + acc,"NO")=="YeS"){
                        document.getElementById('ajaxoutput').innerHTML = "Result:<br>";
                        for(i=0;i<x.length;i++){
                            if(x[i].checked){
                                cntrequest++;
                                massAjax("action=changeaccrole&accid=" + x[i].value + "&roleid=" + document.getElementById('massroleid').value,document.getElementById('u' + x[i].value + 'name').innerHTML);
                            }
                        }
                    }
                }
            }

            function massAjax(data,text){
                var xmlHttp = getxmlHttp();
                xmlHttp.onreadystatechange=function(){
                    if(xmlHttp.readyState==4){
                        cnt++;
                        var pos = xmlHttp.responseText.indexOf("refresh");
                        if(pos>-1 && pos < 10)
                            document.getElementById('ajaxoutput').innerHTML += "Account " + text + " successfully!<br>";
                        else
                            document.getElementById('ajaxoutput').innerHTML += "Account " + text + " failed! " + xmlHttp.responseText + "<br>";
                        if(cnt>=cntrequest)
                            document.getElementById('ajaxoutput').innerHTML += "Click <a href=\\"javascript:window.location.reload()\\">here</a> to reload";
                    }
                };
                xmlHttp.open("GET","ajax.php?" + data,true);
                xmlHttp.send(null);
            }

            
EOT;

    $tpl->addValue("{SCRIPT}", $script);
    $rolelist = $fnc->listAccountRole();
    $content=<<<EOT
            <div class="highslide-html-content" id="menuedit">
                <br>
                <table>
                    <tr>
                        <td>Acc ID</td><td id="accid"></td>
                    </tr>
                    <tr>
                        <td>Username*<br><i>Max length:25 characters</i></td><td><input type="text" id="accuname" size="26" maxlength="25" onchange="ajaxCheckAcc(this);"><span id="accmess"><span></td>
                    </tr>
                    <tr>
                        <td>Role*</td>
                        <td>
                            <select id="accroleid" style="width:100&#37;">
                                $rolelist
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Password*<br><i>Maxlength:50 characters.</i></td><td><input type="text" id="accpass" size="26" maxlength="50"><span id="passmess"><span></td>
                    </tr>
                    <tr>
                        <td>Fullname*</td><td><input type="text" id="accfname" size="26" maxlength="50"></td>
                    </tr>
                    <tr>
                        <td>Email</td><td><input type="text" id="accemail" size="26" maxlength="100"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="button" value="" id="btnaction" onclick="HSE_Close(this.value);">
                            <input type="button" value="Close" id="btnClose" onclick="HSE_Close('none');">
                        </td>
                    </tr>
                </table>
                (*) field are require.
                <br><br>&nbsp;
            </div>
EOT;

    
    
    $page = "1";
    $uname = "";
    if(isset($_GET['page'])){
        $page = $_GET['page'];
    }
    if(isset($_GET['uname'])){
        $uname = $_GET['uname'];
    }
    $content .= "<center>Search username<input type=\"text\" id=\"uname\" value=\"$uname\"><input type=\"button\" value=\"Search\" onclick=\"window.location.href='?uname=' + encodeURIComponent(document.getElementById('uname').value)\"></center>";
    $content .= $fnc->listAccount($page,$uname);
    
    

    $tpl->addValue("{CONTENT}", $content);
    echo $tpl->compileTheme();
?>
Fixed for everyone else.

BTW php + html + javascript, all in one document = fail. If possible, you should really think about splitting everything else up.

Is this a new problem or a recent one? I don't immediately see anything wrong (though, I haven't thoroughly combed over it.)
 
Last edited:

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,658
75
This probably won't work, but...if password changing works...try setting the passmess innerHTML value in ShowHSCreate to "<br>" instead of "".

I haven't delved in deeply; but that's the biggest difference I've seen so far between account creation and everything else, so if no one else comes up with anything it might be worth a shot.
 

potoba

Senior member
Oct 17, 2006
738
0
76
Thank you very much for your inputs. I will try your suggestions when I get home tonight. It used to work before when the server sat in our department. The IT people decided to move our folder to their server and this problem appeared. There are similar phenomena in other pages, but I think if I could fix this one, the other ones should be tweaked the same way.
 
Last edited:

potoba

Senior member
Oct 17, 2006
738
0
76
This probably won't work, but...if password changing works...try setting the passmess innerHTML value in ShowHSCreate to "<br>" instead of "".

I haven't delved in deeply; but that's the biggest difference I've seen so far between account creation and everything else, so if no one else comes up with anything it might be worth a shot.

It didn't work :(
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,695
4,658
75
Alright. Then we'll need to delve deeper into the codebase.

I can't see any problems in this code. It seems to me that the most likely source of the error is in '../include/template.inc.php', in the addValueFromFile function, as it's only called to make the "Add account" button.

I also notice that your code uses the Highslide JS API. It's unlikely but not quite impossible that the bug is either there or in the use of that API.
 

zetsway

Senior member
Nov 8, 2007
721
0
76
BTW php + html + javascript, all in one document = fail. If possible, you should really think about splitting everything else up.

Huh really? I do this all the time. It's not pretty but I do it. So are you saying I should use an includes file for my php or html and external javascript?
 

Cogman

Lifer
Sep 19, 2000
10,286
145
106
Huh really? I do this all the time. It's not pretty but I do it. So are you saying I should use an includes file for my php or html and external javascript?
Yep, that is exactly what I'm saying. I can understand mixing php + html. However, throwing the javascript in there just makes things unnecessarily difficult.

The reason for splitting is simple, it is easier to know what language you are working in. It also helps to promote code reuse. If you've already written something, it is easier to just link into the relevant files and execute them for your execution. As a bonus, if you find a bug in your coding, you only have to change one file to fix the bug in multiple locations.

That, and syntax highlighters will love you :D
 

zetsway

Senior member
Nov 8, 2007
721
0
76
Yep, that is exactly what I'm saying. I can understand mixing php + html. However, throwing the javascript in there just makes things unnecessarily difficult.

The reason for splitting is simple, it is easier to know what language you are working in. It also helps to promote code reuse. If you've already written something, it is easier to just link into the relevant files and execute them for your execution. As a bonus, if you find a bug in your coding, you only have to change one file to fix the bug in multiple locations.

That, and syntax highlighters will love you :D

I see your point. That's the purpose of functions and classes. Sometimes you just get lazy though and it come back to bite you :)
 

iCyborg

Golden Member
Aug 8, 2008
1,350
62
91
To the OP, have you tried using something like FireBug, that allows you to set breakpoints, step through the JS code, inspect objects etc. Never worked with PHP so I don't know if it can handle that, but during my limited experience with JS, FireBug was incredibly useful for debugging compared to "looking into the code and trying to figure out what's wrong".
 

zetsway

Senior member
Nov 8, 2007
721
0
76
To the OP, have you tried using something like FireBug, that allows you to set breakpoints, step through the JS code, inspect objects etc. Never worked with PHP so I don't know if it can handle that, but during my limited experience with JS, FireBug was incredibly useful for debugging compared to "looking into the code and trying to figure out what's wrong".

Firebug just works with JS as far as I know.
 

iCyborg

Golden Member
Aug 8, 2008
1,350
62
91
Yeah, PHP is server-side so it's a no-go for Firebug, forgot to notice that. Still, a large part of the code snippet is JS...
 

zetsway

Senior member
Nov 8, 2007
721
0
76
If this was working before and it just stopped working have you looked at the server? Is it out of space are there logs that needs to be deleted. If code was working and no one modified it than don't get stuck looking at the code.

Troubleshoot: what was the last thing that happened to the web server.
 

potoba

Senior member
Oct 17, 2006
738
0
76
Thanks guys. I'll come down to the It people downstairs today to see if the server was the problem.

I really appreciate your help so far!
 

potoba

Senior member
Oct 17, 2006
738
0
76
Hi guys, one quick question: is it possible that the mySQL server causes this problem?
Thanks
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
You could enable the general log in mysql(outputs all queries) and verify that the queries being executed are the expected ones. This will destroy your mysql performance if your server is busy though, so be careful.
 

zetsway

Senior member
Nov 8, 2007
721
0
76
Seeing how your page is stuck on loading it is possible. Has the server been restarted? Ask someone to check the service logs to see if a service failed to load. Are you able to get to the database? I assume you can because you said everything else is working except the add account function. Once again when did this start happening? Since it was working who was the last person to add an account. Ask them if they notice anything out of the ordinary. Is your database full?

Once you check all these and anything else you can think of, come back to the code. I say this because I wouldn&#8217;t look at code that&#8217;s have been working and one day it stop. Not to say that programmers are perfect but let&#8217;s look at all the variables instead of just one. So don&#8217;t rule this out.

There were some includes files. Did any passwords change? This could affect the add account function.

Keep us updated.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
Wow, before I would even try to debug that I'd get the javascript out into it's own file.
 

potoba

Senior member
Oct 17, 2006
738
0
76
Thanks guys. I am going to be on a business trip for the weekend but I'll go back to work on this when I get back. I really appreciate your kind support! :)