Пример #1
0
function GetcolumnValue($table, $Forgien_Key_Display_Field)
{
    $coulmtype = GetCoulmsInfo($table);
    $primryname = $coulmtype['FieldsName'][0];
    $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
    if ($page <= 0) {
        $page = 1;
    }
    $per_page = 10;
    // Set how many records do you want to display per page.
    $startpoint = $page * $per_page - $per_page;
    $statement = "`{$table}` ORDER BY `{$primryname}` DESC";
    // Change `records` according to your table name.
    $columvalue = QueryResult("SELECT * FROM {$statement} LIMIT {$startpoint} , {$per_page}");
    $counter = 0;
    $itreation_FK = 0;
    $limtbuttonrepeat = 0;
    //get config info
    $confObj = CheckconfigInfo();
    while ($rowvalue = mysql_fetch_row($columvalue)) {
        echo "<form method='POST' action='authentication/deletequery.php' data-form='true' id='myform_{$counter}'><tr>";
        //we check the length to make it fit with the table responsive
        //append the radio button
        echo "<td ><span id='hash'>#</span><input type='radio' name='showrelatedinfo' value='" . $rowvalue[0] . "' style='display:none;margin-top: -2px;opacity: 1;margin-left: 0px;position: inherit;'></td>";
        if (count($rowvalue) < 8) {
            for ($i = 0; $i < count($rowvalue); $i++) {
                //get primry key for the fields less than 8
                $prima = mysql_get_foregin_key($table, $coulmtype['FieldsName'][$i]);
                if ($prima != '') {
                    //get FK tablename and primary key for the forgien key and the display name if exsist and its value
                    $FK = GetForeginKey_TableName($table, $prima);
                    $Tablename_FK = substr($FK[$prima], 0, strpos($FK[$prima], '.'));
                    // add the button to get all info for this primary key from the related table
                    @($fktables = GetForgienTablename_ForSpecific_Tablename($table));
                    @($fktablesname = substr($fktables[$limtbuttonrepeat], 0, strpos($fktables[$limtbuttonrepeat], '.')));
                    @($fkidname = end(explode(".", $fktables[$limtbuttonrepeat])));
                    if ($limtbuttonrepeat < count($fktables) && $fktablesname != '') {
                        echo "<a id='displayrelatedrecords' onclick=\"window.open('authentication/displayrelatedinfo.php?tablename={$table}&relatedinfo={$fktablesname}&fkfieldname={$fkidname}&relatedid={$rowvalue['0']}&true','Display Related Info','scrollbars=1,resizable=1,width=1200,height=640')\" style=\"cursor: pointer;margin-bottom:10px;margin-right:10px;display:none\" class='btn btn-info'>Display " . " " . ucfirst($fktablesname) . "</a> ";
                    }
                    $limtbuttonrepeat++;
                    $PK_Name_For_FK = end(explode(".", $FK[$prima]));
                    $FKNAME = $coulmtype['FieldsName'][$i];
                    $PK_Value_For_FK = $rowvalue[$i];
                    if (!empty($Forgien_Key_Display_Field)) {
                        if (array_key_exists($Tablename_FK, $Forgien_Key_Display_Field)) {
                            $FK_Field_Display = $Forgien_Key_Display_Field[$Tablename_FK];
                            @($FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' "));
                            while (@($FKRow = mysql_fetch_array(@$FK_Query))) {
                                echo "<td>" . $FKRow[$FK_Field_Display] . "</td>";
                            }
                            echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\" display_name=\"{$FK_Field_Display}\" value=\"{$Tablename_FK}\">";
                        } else {
                            $FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' ");
                            while ($FKRow = mysql_fetch_array($FK_Query)) {
                                echo "<td>" . substr($FKRow[0], 0, 60) . "</td>";
                            }
                            echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\"  value=\"{$Tablename_FK}\">";
                        }
                        //end of array has no value for this tablename
                    } else {
                        $FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' ");
                        while ($FKRow = mysql_fetch_array($FK_Query)) {
                            echo "<td>" . substr($FKRow[0], 0, 60) . "</td>";
                        }
                        echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\"  value=\"{$Tablename_FK}\">";
                    }
                } else {
                    //prepare the variables for youtube and viedo and images
                    if (count($confObj) > 0) {
                        if ($confObj['fieldname_image'] != '') {
                            $images = $confObj['fieldname_image'];
                        } else {
                            $images = 'Image';
                        }
                        if ($confObj['youtubefieldname'] != '') {
                            $youtube = $confObj['youtubefieldname'];
                        } else {
                            $youtube = 'YouTube';
                        }
                        if ($confObj['viedofieldname'] != '') {
                            $viedo = $confObj['viedofieldname'];
                        } else {
                            $viedo = 'Video';
                        }
                    } else {
                        $youtube = 'YouTube';
                        $viedo = 'Video';
                        $images = 'Image';
                    }
                    //check for youtube
                    if (preg_match('/' . $youtube . '/', $coulmtype['FieldsName'][$i])) {
                        if (@$rowvalue[$i] != '') {
                            echo "<td><iframe src='{$rowvalue[$i]}' width='130' height='100' frameborder='0' scrolling='no' allowfullscreen></iframe></td>";
                        } else {
                            echo "<td><img src='images/youtube.png' style='width:130px;height:80px;border-radius: 10px;'/></td>";
                        }
                    } else {
                        if (preg_match('/' . $viedo . '/', $coulmtype['FieldsName'][$i])) {
                            if (@$rowvalue[$i] != '') {
                                echo "<td><video width='320' height='240' controls><source src='{$rowvalue[$i]}' type='video/mp4'></video>  </td>";
                            } else {
                                echo "<td><img src='images/video.png' style='width:130px;height:80px;border-radius: 10px;'/></td>";
                            }
                        } else {
                            if (preg_match('/' . $images . '/', $coulmtype['FieldsName'][$i]) && $coulmtype['OrginalFieldType'][$i] != "blob" && $coulmtype['FieldType'][$i] != "text") {
                                //same code for the blob type but we check for the name incase the type is not blob
                                if ($rowvalue[$i] == '') {
                                    echo "<td><img src='images/default.png' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                } else {
                                    echo "<td><img src='authentication/uploads/{$rowvalue[$i]}' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                }
                            } else {
                                if ($coulmtype['OrginalFieldType'][$i] == "blob" && $coulmtype['FieldType'][$i] != "text") {
                                    if ($rowvalue[$i] == '') {
                                        echo "<td><img src='images/default.png' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                    } else {
                                        echo "<td><img src='data:image/jpeg;base64," . base64_encode($rowvalue[$i]) . "' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                    }
                                } else {
                                    echo "<td>" . substr($rowvalue[$i], 0, 40) . "</td>";
                                }
                            }
                        }
                    }
                }
                //end of primary key
                // add the edit and delete at the end of columns
                if ($i == count($rowvalue) - 1) {
                    echo "<input  type='hidden' name='tablename' value='{$table}' />\n                           <input  type='hidden' name='mainid' value='{$rowvalue['0']}' />";
                    echo "<td><a onclick=\"window.open('authentication/ineredit.php?tablename={$table}&edit={$rowvalue['0']}','Update Recors','scrollbars=1,resizable=1,width=600,height=640')\" style=\"cursor: pointer;\">Edit</a></td><td><input  form='myform_{$counter}' type='submit' name='delete' value='Delete' class=\"btn btn-danger\"  style=\"cursor: pointer;\" /></td>";
                }
            }
        } else {
            for ($i = 0; $i < 8; $i++) {
                //get primry key for the fields less than 8
                $prima = mysql_get_foregin_key($table, $coulmtype['FieldsName'][$i]);
                if ($prima != '') {
                    //get FK tablename and primary key for the forgien key and the display name if exsist and its value
                    $FK = GetForeginKey_TableName($table, $prima);
                    $Tablename_FK = substr($FK[$prima], 0, strpos($FK[$prima], '.'));
                    // add the button to get all info for this primary key from the related table
                    @($fktables = GetForgienTablename_ForSpecific_Tablename($table));
                    @($fktablesname = substr($fktables[$limtbuttonrepeat], 0, strpos($fktables[$limtbuttonrepeat], '.')));
                    @($fkidname = end(explode(".", $fktables[$limtbuttonrepeat])));
                    if ($limtbuttonrepeat < count($fktables) && $fktablesname != '') {
                        echo "<a id='displayrelatedrecords' onclick=\"window.open('authentication/displayrelatedinfo.php?tablename={$table}&relatedinfo={$fktablesname}&fkfieldname={$fkidname}&relatedid={$rowvalue['0']}&true','Display Related Info','scrollbars=1,resizable=1,width=1200,height=640')\" style=\"cursor: pointer;margin-bottom:10px;margin-right:10px;display:none\" class='btn btn-info'>Display " . " " . ucfirst($fktablesname) . "</a> ";
                    }
                    $limtbuttonrepeat++;
                    $PK_Name_For_FK = end(explode(".", $FK[$prima]));
                    $FKNAME = $coulmtype['FieldsName'][$i];
                    $PK_Value_For_FK = $rowvalue[$i];
                    if (!empty($Forgien_Key_Display_Field)) {
                        if (array_key_exists($Tablename_FK, $Forgien_Key_Display_Field)) {
                            $FK_Field_Display = $Forgien_Key_Display_Field[$Tablename_FK];
                            @($FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' "));
                            while (@($FKRow = mysql_fetch_array(@$FK_Query))) {
                                echo "<td>" . $FKRow[$FK_Field_Display] . "</td>";
                            }
                            echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\" display_name=\"{$FK_Field_Display}\" value=\"{$Tablename_FK}\">";
                        } else {
                            @($FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' "));
                            while (@($FKRow = mysql_fetch_array(@$FK_Query))) {
                                echo "<td>" . substr($FKRow[0], 0, 60) . "</td>";
                            }
                            echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\"  value=\"{$Tablename_FK}\">";
                        }
                        //end of array has no value for this tablename
                    } else {
                        $FK_Query = QueryResult("SELECT * FROM {$Tablename_FK}  WHERE `{$PK_Name_For_FK}` = '{$PK_Value_For_FK}' ");
                        while ($FKRow = mysql_fetch_array($FK_Query)) {
                            echo "<td>" . substr($FKRow[0], 0, 60) . "</td>";
                        }
                        echo "<input  type=\"hidden\" name=\"Tablename_FK\" prim_key=\"{$PK_Value_For_FK}\"  value=\"{$Tablename_FK}\">";
                    }
                } else {
                    //prepare the variables for youtube and viedo and images
                    if (count($confObj) > 0) {
                        if ($confObj['fieldname_image'] != '') {
                            $images = $confObj['fieldname_image'];
                        } else {
                            $images = 'Image';
                        }
                        if ($confObj['youtubefieldname'] != '') {
                            $youtube = $confObj['youtubefieldname'];
                        } else {
                            $youtube = 'YouTube';
                        }
                        if ($confObj['viedofieldname'] != '') {
                            $viedo = $confObj['viedofieldname'];
                        } else {
                            $viedo = 'Video';
                        }
                    } else {
                        $youtube = 'YouTube';
                        $viedo = 'Video';
                        $images = 'Image';
                    }
                    //check for youtube
                    if (preg_match('/' . $youtube . '/', $coulmtype['FieldsName'][$i])) {
                        if (@$rowvalue[$i] != '') {
                            echo "<td><iframe src='{$rowvalue[$i]}' width='130' height='100' frameborder='0' scrolling='no' allowfullscreen></iframe></td>";
                        } else {
                            echo "<td><img src='images/youtube.png' style='width:130px;height:80px;border-radius: 10px;'/></td>";
                        }
                    } else {
                        if (preg_match('/' . $viedo . '/', $coulmtype['FieldsName'][$i])) {
                            if (@$rowvalue[$i] != '') {
                                echo "<td><video width='320' height='240' controls><source src='{$rowvalue[$i]}' type='video/mp4'></video>  </td>";
                            } else {
                                echo "<td><img src='images/video.png' style='width:130px;height:80px;border-radius: 10px;'/></td>";
                            }
                        } else {
                            if (preg_match('/' . $images . '/', $coulmtype['FieldsName'][$i]) && $coulmtype['OrginalFieldType'][$i] != "blob" && $coulmtype['FieldType'][$i] != "text") {
                                //same code for the blob type but we check for the name incase the type is not blob
                                if ($rowvalue[$i] == '') {
                                    echo "<td><img src='images/default.png' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                } else {
                                    echo "<td><img src='authentication/uploads/{$rowvalue[$i]}' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                }
                            } else {
                                if ($coulmtype['OrginalFieldType'][$i] == "blob" && $coulmtype['FieldType'][$i] != "text") {
                                    if ($rowvalue[$i] == '') {
                                        echo "<td><img src='images/default.png' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                    } else {
                                        echo "<td><img src='data:image/jpeg;base64," . base64_encode($rowvalue[$i]) . "' style='width:80px;height:80px;border-radius: 10px;'/></td>";
                                    }
                                } else {
                                    echo "<td>" . substr($rowvalue[$i], 0, 40) . "</td>";
                                }
                            }
                        }
                    }
                }
                //end of primary key
                // add the edit and delete at the end of columns
                if ($i == 8 - 1) {
                    echo "<input  type='hidden' name='tablename' value='{$table}' />\n                           <input  type='hidden' name='mainid' value='{$rowvalue['0']}' />\n                           <td><a onclick=\"window.open('authentication/ineredit.php?tablename={$table}&edit={$rowvalue['0']}','Update Records','scrollbars=1,resizable=1,width=600,height=640')\" style=\"cursor: pointer;\">Edit</a></td><td><input  form='myform_{$counter}' type='submit' name='delete' value='Delete' class=\"btn btn-danger\"  style=\"cursor: pointer;\" /></td>";
                }
            }
        }
        //end of if number of col more less than 8
        echo "</tr></form>";
        $counter++;
    }
    //end of while loop
    // displaying paginaiton.
    echo pagination($statement, $per_page, $page, $url = '?', $table);
}
Пример #2
0
     $images = 'Image';
     $uploads = 'uploads/';
     $password = '******';
 }
 //draw the submit form
 for ($i = 0; $i <= @$colum_submit_number - 1; $i++) {
     //check if the name is primary key and not display it
     if ($colum_submit_name_no_replace[$i] != @$PrimryKey_DisplayName) {
         //get the forgien key if exsist
         $FK = mysql_get_foregin_key($tablename, $table_submit_info['FieldsName'][$i]);
         //check if the field now is one of the forgien keys
         if ($FK != '' && $colum_submit_name_no_replace[$i] == $FK) {
             //get table name for the fk and select * from table by field name if exsist
             //databas name to get all FK
             $FK_Fields_Name = $colum_submit_name_no_replace[$i];
             $All_FK_TableName = GetForeginKey_TableName($tablename, $FK);
             $Tablename_FK = substr($All_FK_TableName[$FK_Fields_Name], 0, strpos($All_FK_TableName[$FK_Fields_Name], '.'));
             $PK_Name_For_FK = end(explode(".", $All_FK_TableName[$FK_Fields_Name]));
             $FK_PK = GetCoulmsInfo($Tablename_FK);
             $PK_Name_For_FK = $FK_PK['primrykeyname'];
             //get * from this table if display name if empty
             //the FK Field Should be Displayed by user
             if (!empty($Forgien_Key_Display_Field)) {
                 //get the displayed forgien key name
                 if (array_key_exists($Tablename_FK, $Forgien_Key_Display_Field)) {
                     $FK_Field_Display = $Forgien_Key_Display_Field[$Tablename_FK];
                     //get the value that already selected in the main table
                     $FK_Value_Query = mysql_query("SELECT * FROM  {$Tablename_FK}  ");
                     //append the dropdown list
                     echo "<div class='form-group' >\n\t\t\t\t\t\t\t\t\t<label for='input-rounded' class='col-sm-2 control-label'>" . $colum_submit_name[$i] . "</label>\n\t\t\t\t\t\t\t\t\t<div class='col-sm-10'>\n\t\t\t\t\t\t\t\t\t    <select name='{$colum_submit_name_no_replace[$i]}' id='{$colum_submit_name_no_replace[$i]}' >";
                     //now get the rest of value from the same table