CVE-2014-125034 (PHP, published 2023-01-02T11:15Z)
Description: value: A vulnerability has been found in stiiv contact_app and classified as problematic. Affected by this vulnerability is the function render of the file libs/View.php. The manipulation of the argument var leads to cross site scripting. The attack can be launched remotely. The patch is named 67bec33f559da9d41a1b45eb9e992bd8683a7f8c. It is recommended to apply a patch to fix this issue. The associated identifier of this vulnerability is VDB-217183.
Severity: nan (CVSS v3 base score: 6.1)
Weakness: CWE-79 \u2014 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.
Repository: https://github.com/stiiv/contact_app
Files changed:
.htaccess
.idea/.name
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/stiiv-mvc.iml
.idea/vcs.xml
.idea/workspace.xml
contact_app.sql
controllers/contacts_controller.php
controllers/error_controller.php
controllers/main_controller.php
controllers/test_controller.php
helpers/Input.php
helpers/Pagination.php
helpers/Session.php
helpers/User.php
includes/config.php
includes/functions.php
index.php
libs/Bootstrap.php
libs/Controller.php
libs/DB.php
libs/Model.php
libs/View.php
models/contact_model.php
models/main_model.php
public/css/style.css
public/js/default.js~
public/js/main.js
public/templates/footer.php
public/templates/header.php
public/templates/navigation.php
public/templates/whole.php
views/contacts.php
views/edit.php
views/error.php
views/insert.php
views/main.php
views/success.php
views/test_view.php
views/update.php
views/view_contact.php
Commit message: Updated view.php

I put htmlspecialchars() into the var_check to avoid the XSS injection.

Vulnerable code:

Fixed code:
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Options -Indexes
stiiv-mvc
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectRootManager" version="2" />
</project>

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ProjectModuleManager">
    <modules>
      <module fileurl="file://$PROJECT_DIR$/.idea/stiiv-mvc.iml" filepath="$PROJECT_DIR$/.idea/stiiv-mvc.iml" />
    </modules>
  </component>
</project>

<component name="DependencyValidationManager">
  <state>
    <option name="SKIP_IMPORT_STATEMENTS" value="false" />
  </state>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
  <component name="NewModuleRootManager">
    <content url="file://$MODULE_DIR$" />
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="VcsDirectoryMappings">
    <mapping directory="" vcs="" />
  </component>
</project>

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="ChangeListManager">
    <list default="true" id="252b63e4-2b6a-48d2-9d6d-813252891a95" name="Default" comment="" />
    <ignored path="stiiv-mvc.iws" />
    <ignored path=".idea/workspace.xml" />
    <option name="TRACKING_ENABLED" value="true" />
    <option name="SHOW_DIALOG" value="false" />
    <option name="HIGHLIGHT_CONFLICTS" value="true" />
    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
    <option name="LAST_RESOLUTION" value="IGNORE" />
  </component>
  <component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
  <component name="CreatePatchCommitExecutor">
    <option name="PATCH_PATH" value="" />
  </component>
  <component name="DaemonCodeAnalyzer">
    <disable_hints />
  </component>
  <component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
  <component name="FavoritesManager">
    <favorites_list name="stiiv-mvc" />
  </component>
  <component name="FileEditorManager">
    <leaf>
      <file leaf-file-name="contact_model.php" pinned="false" current="false" current-in-tab="false">
        <entry file="file://$PROJECT_DIR$/models/contact_model.php">
          <provider selected="true" editor-type-id="text-editor">
            <state line="26" column="36" selection-start="746" selection-end="746" vertical-scroll-proportion="0.0" vertical-offset="598" max-vertical-offset="3151">
              <folding />
            </state>
          </provider>
        </entry>
      </file>
      <file leaf-file-name="contacts_controller.php" pinned="false" current="true" current-in-tab="true">
        <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
          <provider selected="true" editor-type-id="text-editor">
            <state line="102" column="83" selection-start="3655" selection-end="3655" vertical-scroll-proportion="0.6313726" vertical-offset="1863" max-vertical-offset="7153">
              <folding />
            </state>
          </provider>
        </entry>
      </file>
    </leaf>
  </component>
  <component name="FindManager">
    <FindUsagesManager>
      <setting name="OPEN_NEW_TAB" value="false" />
    </FindUsagesManager>
  </component>
  <component name="IdeDocumentHistory">
    <option name="changedFiles">
      <list>
        <option value="$PROJECT_DIR$/libs/Controller.php" />
        <option value="$PROJECT_DIR$/controllers/test_controller.php" />
        <option value="$PROJECT_DIR$/public/templates/whole.php" />
        <option value="$PROJECT_DIR$/libs/Bootstrap.php" />
        <option value="$PROJECT_DIR$/controllers/error_controller.php" />
        <option value="$PROJECT_DIR$/includes/config.php" />
        <option value="$PROJECT_DIR$/libs/Validate.php" />
        <option value="$PROJECT_DIR$/libs/View.php" />
        <option value="$PROJECT_DIR$/libs/Input.php" />
        <option value="$PROJECT_DIR$/includes/functions.php" />
        <option value="$PROJECT_DIR$/views/success.php" />
        <option value="$PROJECT_DIR$/libs/Model.php" />
        <option value="$PROJECT_DIR$/views/error.php" />
        <option value="$PROJECT_DIR$/public/templates/footer.php" />
        <option value="$PROJECT_DIR$/views/view_contact.php" />
        <option value="$PROJECT_DIR$/public/css/style.css" />
        <option value="$PROJECT_DIR$/views/insert.php" />
        <option value="$PROJECT_DIR$/views/search.php" />
        <option value="$PROJECT_DIR$/models/contact_model.php" />
        <option value="$PROJECT_DIR$/views/contacts.php" />
        <option value="$PROJECT_DIR$/libs/Pagination.php" />
        <option value="$PROJECT_DIR$/public/templates/navigation.php" />
        <option value="$PROJECT_DIR$/public/templates/header.php" />
        <option value="$PROJECT_DIR$/controllers/contacts_controller.php" />
      </list>
    </option>
  </component>
  <component name="PhpWorkspaceProjectConfiguration" backward_compatibility_performed="true" />
  <component name="ProjectFrameBounds">
    <option name="x" value="60" />
    <option name="y" value="102" />
    <option name="width" value="1144" />
    <option name="height" value="936" />
  </component>
  <component name="ProjectLevelVcsManager" settingsEditedManually="false">
    <OptionsSetting value="true" id="Add" />
    <OptionsSetting value="true" id="Remove" />
    <OptionsSetting value="true" id="Checkout" />
    <OptionsSetting value="true" id="Update" />
    <OptionsSetting value="true" id="Status" />
    <OptionsSetting value="true" id="Edit" />
    <ConfirmationsSetting value="0" id="Add" />
    <ConfirmationsSetting value="0" id="Remove" />
  </component>
  <component name="ProjectReloadState">
    <option name="STATE" value="0" />
  </component>
  <component name="ProjectView">
    <navigator currentView="ProjectPane" proportions="" version="1" splitterProportion="0.5">
      <flattenPackages />
      <showMembers />
      <showModules />
      <showLibraryContents />
      <hideEmptyPackages />
      <abbreviatePackageNames />
      <autoscrollToSource />
      <autoscrollFromSource />
      <sortByType />
    </navigator>
    <panes>
      <pane id="ProjectPane">
        <subPane>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="views" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="public" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="templates" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="public" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="public" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="images" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="public" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="css" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="libs" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
          <PATH>
            <PATH_ELEMENT>
              <option name="myItemId" value="stiiv-mvc" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="contact_app" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
            <PATH_ELEMENT>
              <option name="myItemId" value="controllers" />
              <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
            </PATH_ELEMENT>
          </PATH>
        </subPane>
      </pane>
      <pane id="Scope" />
    </panes>
  </component>
  <component name="PropertiesComponent">
    <property name="WebServerToolWindowFactoryState" value="false" />
    <property name="FullScreen" value="false" />
    <property name="last_opened_file_path" value="$PROJECT_DIR$/../stiiv-mvc" />
    <property name="SearchEverywhereHistory" value="&gt;" />
  </component>
  <component name="RunManager">
    <configuration default="true" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
      <TestRunner />
      <method />
    </configuration>
    <configuration default="true" type="PhpLocalRunConfigurationType" factoryName="PHP Console">
      <method />
    </configuration>
    <configuration default="true" type="JavascriptDebugType" factoryName="JavaScript Debug" singleton="true">
      <method />
    </configuration>
    <configuration default="true" type="PhpUnitRemoteRunConfigurationType" factoryName="PHPUnit on Server">
      <method />
    </configuration>
    <list size="0" />
  </component>
  <component name="ShelveChangesManager" show_recycled="false" />
  <component name="TaskManager">
    <task active="true" id="Default" summary="Default task">
      <changelist id="252b63e4-2b6a-48d2-9d6d-813252891a95" name="Default" comment="" />
      <created>1410271434189</created>
      <updated>1410271434189</updated>
    </task>
    <servers />
  </component>
  <component name="TodoView" selected-index="0">
    <todo-panel id="selected-file">
      <are-packages-shown value="false" />
      <are-modules-shown value="false" />
      <flatten-packages value="false" />
      <is-autoscroll-to-source value="false" />
    </todo-panel>
    <todo-panel id="all">
      <are-packages-shown value="false" />
      <are-modules-shown value="false" />
      <flatten-packages value="false" />
      <is-autoscroll-to-source value="false" />
    </todo-panel>
    <todo-panel id="default-changelist">
      <are-packages-shown value="false" />
      <are-modules-shown value="false" />
      <flatten-packages value="false" />
      <is-autoscroll-to-source value="false" />
    </todo-panel>
  </component>
  <component name="ToolWindowManager">
    <frame x="60" y="102" width="1144" height="936" extended-state="0" />
    <editor active="false" />
    <layout>
      <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
      <window_info id="Terminal" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.27780822" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" x="72" y="408" width="1825" height="316" />
      <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32916668" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
      <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.329863" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
      <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
      <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.25409836" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
      <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
      <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
      <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="8" side_tool="true" content_ui="tabs" />
      <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
      <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
      <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
      <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
      <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
      <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
      <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
      <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
      <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
    </layout>
  </component>
  <component name="Vcs.Log.UiProperties">
    <option name="RECENTLY_FILTERED_USER_GROUPS">
      <collection />
    </option>
  </component>
  <component name="VcsContentAnnotationSettings">
    <option name="myLimit" value="2678400000" />
  </component>
  <component name="VcsManagerConfiguration">
    <option name="myTodoPanelSettings">
      <TodoPanelSettings />
    </option>
  </component>
  <component name="XDebuggerManager">
    <breakpoint-manager />
  </component>
  <component name="editorHistoryManager">
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="89" column="83" selection-start="3160" selection-end="3160" vertical-scroll-proportion="0.0" vertical-offset="1564" max-vertical-offset="4922">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/contacts.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="1" column="54" selection-start="77" selection-end="77" vertical-scroll-proportion="0.0" vertical-offset="23" max-vertical-offset="1012" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="95" column="47" selection-start="1921" selection-end="1921" vertical-scroll-proportion="0.0" vertical-offset="2185" max-vertical-offset="2737" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/includes/config.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="11" column="33" selection-start="283" selection-end="283" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="1449">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="24" column="76" selection-start="802" selection-end="802" vertical-scroll-proportion="0.0" vertical-offset="552" max-vertical-offset="1840" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="23" column="43" selection-start="651" selection-end="651" vertical-scroll-proportion="0.0" vertical-offset="529" max-vertical-offset="759">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="36" column="81" selection-start="1026" selection-end="1026" vertical-scroll-proportion="0.0" vertical-offset="828" max-vertical-offset="1403" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="493" selection-end="493" vertical-scroll-proportion="0.0" vertical-offset="391" max-vertical-offset="598">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="21" column="34" selection-start="565" selection-end="565" vertical-scroll-proportion="0.0" vertical-offset="483" max-vertical-offset="782" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="36" column="61" selection-start="950" selection-end="950" vertical-scroll-proportion="0.0" vertical-offset="828" max-vertical-offset="1288" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="76" column="25" selection-start="1589" selection-end="1589" vertical-scroll-proportion="0.0" vertical-offset="1127" max-vertical-offset="2737" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="493" selection-end="493" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="598">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="21" column="34" selection-start="565" selection-end="565" vertical-scroll-proportion="0.0" vertical-offset="483" max-vertical-offset="782" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="45" column="7" selection-start="1112" selection-end="1112" vertical-scroll-proportion="0.0" vertical-offset="1035" max-vertical-offset="1173" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="26" column="42" selection-start="633" selection-end="633" vertical-scroll-proportion="0.0" vertical-offset="598" max-vertical-offset="2691" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="493" selection-end="493" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="598">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="21" column="34" selection-start="565" selection-end="565" vertical-scroll-proportion="0.0" vertical-offset="483" max-vertical-offset="782" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="45" column="7" selection-start="1112" selection-end="1112" vertical-scroll-proportion="0.0" vertical-offset="1035" max-vertical-offset="1173" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="24" column="30" selection-start="544" selection-end="544" vertical-scroll-proportion="0.0" vertical-offset="552" max-vertical-offset="2576" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="493" selection-end="493" vertical-scroll-proportion="0.0" vertical-offset="391" max-vertical-offset="598">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="18" column="82" selection-start="423" selection-end="423" vertical-scroll-proportion="0.0" vertical-offset="414" max-vertical-offset="782" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="45" column="7" selection-start="1112" selection-end="1112" vertical-scroll-proportion="0.0" vertical-offset="1035" max-vertical-offset="1173" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="20" column="9" selection-start="428" selection-end="428" vertical-scroll-proportion="0.0" vertical-offset="69" max-vertical-offset="2024" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="493" selection-end="493" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="598">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="18" column="82" selection-start="423" selection-end="423" vertical-scroll-proportion="0.0" vertical-offset="414" max-vertical-offset="782" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="45" column="7" selection-start="1112" selection-end="1112" vertical-scroll-proportion="0.0" vertical-offset="1035" max-vertical-offset="1173" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="52" column="24" selection-start="912" selection-end="912" vertical-scroll-proportion="0.0" vertical-offset="1196" max-vertical-offset="1679" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/js/main.js">
      <provider selected="true" editor-type-id="text-editor">
        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="902" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/test_view.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="2" column="27" selection-start="125" selection-end="125" vertical-scroll-proportion="-1.4375" vertical-offset="0" max-vertical-offset="184" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/test_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="7" column="86" selection-start="236" selection-end="236" vertical-scroll-proportion="0.1792873" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/whole.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="5" column="35" selection-start="176" selection-end="176" vertical-scroll-proportion="0.12806237" vertical-offset="0" max-vertical-offset="920" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/libs/Controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="5" column="22" selection-start="75" selection-end="75" vertical-scroll-proportion="0.12806237" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/libs/View.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="49" column="7" selection-start="1272" selection-end="1272" vertical-scroll-proportion="0.7951002" vertical-offset="413" max-vertical-offset="1311">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="jar://$APPLICATION_HOME_DIR$/plugins/php/lib/php.jar!/com/jetbrains/php/lang/psi/stubs/data/Core_d.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="313" column="34" selection-start="8233" selection-end="8234" vertical-scroll-proportion="0.7037862" vertical-offset="6567" max-vertical-offset="8349">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/includes/functions.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="35" column="67" selection-start="908" selection-end="908" vertical-scroll-proportion="0.56458795" vertical-offset="298" max-vertical-offset="1426" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/success.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="6" column="79" selection-start="337" selection-end="337" vertical-scroll-proportion="0.15367483" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/libs/Model.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="18" column="39" selection-start="437" selection-end="437" vertical-scroll-proportion="0.41091314" vertical-offset="45" max-vertical-offset="966" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/error_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="8" column="55" selection-start="228" selection-end="228" vertical-scroll-proportion="0.20489977" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/error.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="2" column="57" selection-start="177" selection-end="177" vertical-scroll-proportion="0.051224943" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/footer.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="3" column="34" selection-start="58" selection-end="58" vertical-scroll-proportion="0.07683741" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/view_contact.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="3" column="34" selection-start="95" selection-end="95" vertical-scroll-proportion="0.0779661" vertical-offset="0" max-vertical-offset="1403" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/css/style.css">
      <provider selected="true" editor-type-id="text-editor">
        <state line="119" column="20" selection-start="2414" selection-end="2414" vertical-scroll-proportion="0.455914" vertical-offset="2313" max-vertical-offset="5152" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/includes/config.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="29" column="71" selection-start="708" selection-end="708" vertical-scroll-proportion="0.3452116" vertical-offset="265" max-vertical-offset="1357">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/insert.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="3" column="10" selection-start="198" selection-end="198" vertical-scroll-proportion="0.07683741" vertical-offset="0" max-vertical-offset="1955" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/libs/DB.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="-0.76837415" vertical-offset="690" max-vertical-offset="4945" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/views/contacts.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="1" column="54" selection-start="77" selection-end="77" vertical-scroll-proportion="0.025612472" vertical-offset="0" max-vertical-offset="1012" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/models/contact_model.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="26" column="36" selection-start="746" selection-end="746" vertical-scroll-proportion="0.0" vertical-offset="598" max-vertical-offset="3151">
          <folding />
        </state>
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/libs/Bootstrap.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="66" column="28" selection-start="1949" selection-end="1949" vertical-scroll-proportion="1.6904231" vertical-offset="0" max-vertical-offset="1748" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/navigation.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="3" column="5" selection-start="174" selection-end="174" vertical-scroll-proportion="0.07683741" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/public/templates/header.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="17" column="38" selection-start="356" selection-end="356" vertical-scroll-proportion="0.43541202" vertical-offset="0" max-vertical-offset="898" />
      </provider>
    </entry>
    <entry file="file://$PROJECT_DIR$/controllers/contacts_controller.php">
      <provider selected="true" editor-type-id="text-editor">
        <state line="102" column="83" selection-start="3655" selection-end="3655" vertical-scroll-proportion="0.6313726" vertical-offset="1863" max-vertical-offset="7153">
          <folding />
        </state>
      </provider>
    </entry>
  </component>
</project>

-- MySQL dump 10.13  Distrib 5.5.40, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: contact_app
-- ------------------------------------------------------
-- Server version	5.5.40-0ubuntu0.14.04.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `contacts`
--

DROP TABLE IF EXISTS `contacts`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `contacts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_user` int(11) NOT NULL DEFAULT '1',
  `ime` varchar(20) NOT NULL,
  `prezime` varchar(32) DEFAULT NULL,
  `mob1` varchar(10) DEFAULT NULL,
  `mob2` varchar(10) DEFAULT NULL,
  `kucni` varchar(10) DEFAULT NULL,
  `posao` varchar(10) DEFAULT NULL,
  `slika` varchar(255) NOT NULL DEFAULT 'default.jpg',
  `opis` text,
  `id_grad` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `contacts`
--

LOCK TABLES `contacts` WRITE;
/*!40000 ALTER TABLE `contacts` DISABLE KEYS */;
INSERT INTO `contacts` VALUES (13,2,'Lima','','095333444','','','','default.jpg',' Some kid from the block',37),(14,4,'Mrki','','','','016553985','','default.jpg','Prijatelj iz osnovne škole.',75),(24,1,'Mare Zg','','1351546546','','','','default.jpg','                                                                                                                                                            ',37),(25,1,'Maša','Mrkić','','','1656161','','default.jpg','                                                                                                        ',NULL),(27,1,'Mrki','','1635465416','','','','default.jpg','',43),(35,1,'Hrco P','','26265454','','','','28.03.2009.piranha25.jpg','                                                        OŠ SAVSKI GAJ                                                                   ',NULL),(36,1,'Nina','','','','1635465465','','default.jpg','',37),(37,1,'Gringo','','','032569877','','','default.jpg','                                                                                                                                                                                                                ',64),(38,1,'Grga Ana','','','','0246546468','','28.03.2009.piranha23.jpg','                                                    ',8);
/*!40000 ALTER TABLE `contacts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `gradovi`
--

DROP TABLE IF EXISTS `gradovi`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `gradovi` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `zip` char(5) NOT NULL,
  `ime` varchar(32) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `gradovi`
--

LOCK TABLES `gradovi` WRITE;
/*!40000 ALTER TABLE `gradovi` DISABLE KEYS */;
INSERT INTO `gradovi` VALUES (1,'10000','Zagreb'),(2,'10290','Zaprešić'),(3,'10310','Ivanić Grad'),(4,'10340','Vrbovec'),(5,'10370','Dugo Selo'),(6,'10380','Sveti Ivan Zelina'),(7,'10410','Velika Gorica'),(8,'10430','Samobor'),(9,'10431','Sveta Nedelja'),(10,'10450','Jastrebarsko'),(11,'20000','Dubrovnik'),(12,'20260','Korčula'),(13,'20340','Ploče'),(14,'20350','Metković'),(15,'20355','Opuzen'),(16,'21000','Split'),(17,'21210','Solin'),(18,'21220','Trogir'),(19,'21230','Sinj'),(20,'21236','Vrlika'),(21,'21240','Trilj'),(22,'21260','Imotski'),(23,'21276','Vrgorac'),(24,'21300','Makarska'),(25,'21310','Omiš'),(26,'21400','Supetar'),(27,'21450','Hvar'),(28,'21460','Stari Grad'),(29,'21480','Vis'),(30,'21485','Komiža'),(31,'22000','Šibenik'),(32,'22211','Vodice'),(33,'22222','Skradin'),(34,'22300','Knin'),(35,'22320','Drniš'),(36,'23000','Zadar'),(37,'23210','Biograd na Moru'),(38,'23232','Nin'),(39,'23250','Pag'),(40,'23420','Benkovac'),(41,'23450','Obrovac'),(42,'31000','Osijek'),(43,'31300','Beli Manastir'),(44,'31400','Đakovo'),(45,'31500','Našice'),(46,'31540','Donji Miholjac'),(47,'31550','Valpovo'),(48,'31551','Belišće'),(49,'32000','Vukovar'),(50,'32100','Vinkovci'),(51,'32236','Ilok'),(52,'32252','Otok'),(53,'32270','Županja'),(54,'33000','Virovitica'),(55,'33515','Orahovica'),(56,'33520','Slatina'),(57,'34000','Požega'),(58,'34310','Pleternica'),(59,'34340','Kutjevo'),(60,'34550','Pakrac'),(61,'34551','Lipik'),(62,'35000','Slavonski Brod'),(63,'35400','Nova Gradiška'),(64,'40000','Čakovec'),(65,'40315','Mursko Središće'),(66,'40323','Prelog'),(67,'42000','Varaždin'),(68,'42220','Novi Marof'),(69,'42223','Varaždinske Toplice'),(70,'42230','Ludbreg'),(71,'42240','Ivanec'),(72,'42250','Lepoglava'),(73,'43000','Bjelovar'),(74,'43240','Čazma'),(75,'43280','Garešnica'),(76,'43290','Grubišno Polje'),(77,'43500','Daruvar'),(78,'44000','Sisak'),(79,'44250','Petrinja'),(80,'44320','Kutina'),(81,'44330','Novska'),(82,'44400','Glina'),(83,'44430','Hrvatska Kostajnica'),(84,'47000','Karlovac'),(85,'47240','Slunj'),(86,'47250','Duga Resa'),(87,'47280','Ozalj'),(88,'47300','Ogulin'),(89,'48000','Koprivnica'),(90,'48260','Križevci'),(91,'48350','&#272;ur&#273;evac'),(92,'49000','Krapina'),(93,'49210','Zabok'),(94,'49218','Pregrada'),(95,'49240','Donja Stubica'),(96,'49243','Oroslavje'),(97,'49250','Zlatar'),(98,'49290','Klanjec'),(99,'51000','Rijeka'),(100,'51215','Kastav'),(101,'51222','Bakar'),(102,'51250','Novi Vinodolski'),(103,'51260','Crikvenica'),(104,'51262','Kraljevica'),(105,'51280','Rab'),(106,'51300','Delnice'),(107,'51306','Čabar'),(108,'51326','Vrbovsko'),(109,'51410','Opatija'),(110,'51500','Krk'),(111,'51550','Mali Lošinj'),(112,'51557','Cres'),(113,'52000','Pazin'),(114,'52100','Pula'),(115,'52210','Rovinj'),(116,'52215','Vodnjan'),(117,'52220','Labin'),(118,'52420','Buzet'),(119,'52440','Poreč'),(120,'52460','Buje'),(121,'52466','Novigrad'),(122,'52470','Umag'),(123,'53000','Gospić'),(124,'53220','Otočac'),(125,'53270','Senj'),(126,'53291','Novalja');
/*!40000 ALTER TABLE `gradovi` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `users`
--

DROP TABLE IF EXISTS `users`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `users` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) NOT NULL,
  `password` varchar(255) NOT NULL,
  `first_name` varchar(20) NOT NULL,
  `last_name` varchar(30) NOT NULL,
  `email` varchar(60) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `users`
--

LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'stiiv85','$2y$10$dhwBY66XvPbkQ52sgUfu6edE6053FKESiuOree0/JlhGg.EshvrJu','Ivan','Stipić Stiiv','ivan.stipic6@gmail.com'),(2,'kstipic','$2y$10$IC3aEDcZXkuE7vGz91u05OJyO897p6XQjpl.WiutJp2rSR9TjTEba','Krešo','Stipić','kstipic@gmail.com'),(3,'mate95','$2y$10$csNC/lXJMMu5MeSTb1h0hO3pfzSDb2gBdB.HWIbLTReegpxPTEbq6','Mate','Granić','mate95@hotmail.com'),(4,'domsi94','$2y$10$uLdRqXTtczs6suzFJ8n9nuLAhzwjoxU.ulWBhCEiSdo4Vh48uaYdS','Domagoj','Stipić','dstipic@gmail.com'),(5,'mario35','$2y$10$PHQ.WnVpq2uEOiNsyePjb.QRLdz.0aX9e84WYZ/mdhhAx2dXFHLMG','Mario','Pekmezić','mario.pek@domain.com');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2014-11-07 14:48:46
<?php

class Contacts extends Controller {

    // control how much results per page
    public $per_page = 3;

    // store contacts values for saving in database
    protected $_contact_vals;

    public function __construct() {
        if(!Session::get("id_user")) {
            redir_to('main');
        }
        parent::__construct();
        $this->_load_model('contact');
        $this->data("username::".$this->model->get_username());
    }

    public function index() {
        $this->view->title = "Kontakti";
        $this->_contact_check();
        $this->_action_message();
        $this->view->render('contacts');
    }

    protected function _action_message() {
        $message = ( Session::get('action_message') != null ) ? Session::get('action_message') : false;
        if($message) {
            $this->data(array(
                'succ_or_err' => 'success',
                'action_message' => $message
            ));
            unset($_SESSION['succ_or_err'], $_SESSION['action_message']);
        }
    }

    public function search() {
        if(FORM_SUBMIT == "POST") {
            $input = new Input();
            $query = $input->escape($_POST["search"]);
            unset($input);
            $this->view->title = "Kontakti";
            if( $this->model->is_search($query) ) {
                $this->view->data["contacts"] = $this->model->search_query($query);
                $this->view->data["contact_num"] = $this->model->countRes();
                $this->view->data["results_num"] = "Pronađeno rezultata";
            } else {
                $this->view->data["results_num"] = "Pronađeno rezultata";
                $this->view->data["no_contacts"] = "Niti jedan resultat nije pronađen";
            }
            $this->view->render('contacts');
        } else {
            redir_to('error');
        }
    }

    /**
     * Check if contacts exist
     */
    protected function _contact_check() {
        if( $this->model->has_results() ) {
            $this->view->data["contacts"] = $this->model->get_all_contacts();
            $this->view->data["contact_num"] = $this->model->total_contacts();
            $this->view->data["results_num"] = "Kontakti ukupno";
            $this->view->data["pagination"] = $this->_paginate();
        } else {
            $this->view->data["results_num"] = "Kontakti ukupno";
            $this->view->data["no_contacts"] = "Kontakt lista je prazna";
        }
    }

    /**
     * Check and return string if pagination is needed
     * @return string | void
     */
    protected function _paginate() {
        $html = "";
        $current_page = (int)( isset($_GET['page']) && is_numeric($_GET['page']) ) ? $_GET['page'] : 1;
        $per_page = $this->per_page;
        $total = $this->model->total_contacts();

        $paginate = new Pagination($current_page, $per_page, $total);

        // check if the page needs pagination
        if( $paginate->needs_pagination() ) {
            $this->view->data["contacts"] = $this->model->get_all_contacts($per_page, $paginate->offset());

            if( $paginate->has_prev_page() ) {
                $html .= '<a href="?page='.$paginate->prev_page().'">&xlarr; Previous</a>';
            }
                

            for($i = 1; $i <= $paginate->total_pages(); $i++) {
                if($current_page == $i) {
                    $html .= '<span>'.$i.'</span>';
                } else {
                    $html .= '<a href="?page='.$i.'">'.$i.'</a>';
                }
            }

            if( $paginate->has_next_page() ) {
                $html .= '<a href="?page='.$paginate->next_page().'">Next &xrarr;</a>';
            }
                
            return $html;

        } else { // there is no need for pagination
            $this->view->data["contacts"] = $this->model->get_all_contacts();
        }

    }

    public function view($id) {
        $id = (int)$id;
        //pretty_print($this->model->view_contact($id));
        $this->view->title = "Detalji";
        $this->view->data["contact"] = $this->model->view_contact($id);
        $this->view->render('view_contact');
    }

    public function insert() {
        $this->view->title = "Unesi novi kontakt";
        $this->view->data["form_title"] = "Unesite novi kontakt";
        $this->view->data["cities"] = $this->model->get_cities();
        $this->_insert_message();
        $this->view->render('insert');
    }

    protected function _insert_message() {
        $message = ( Session::get('errorMsg') != null ) ? Session::get('errorMsg') : false;
        if($message) {
            $this->data(array(
                'succ_or_err' => 'success',
                'errorMsg' => $message
            ));
            unset($_SESSION['succ_or_err'], $_SESSION['errorMsg'], $_POST);
        }
    }

    public function save() {
        if(FORM_SUBMIT == "POST") {
            $input = new Input();
            // if these fields are empty, do not safe anything
            if( empty($_POST['mob1']) && empty($_POST['mob2']) && empty($_POST['home_tel']) && empty($_POST['job_tel']) ) {
                $this->view->data["succ_or_err"] = "failure";
                $this->view->data["errorMsg"] = "Nema podataka za spremanje. Barem jedan broj mora biti unešen.";
                $this->insert();
                return;
            }
    // save to the database
            if( $this->_validate_input($input) ) {
                $this->_save_to_db();
                Session::multi_set(array(
                    'succ_or_err' => 'success',
                    'errorMsg' => 'Kontakt uspješno spremljen'
                ));
                redir_to('contacts/insert');

            } else { // display existing errors
                $this->view->data["succ_or_err"] = "failure";
                $this->view->data["errorMsg"] = $input->get_formatted_errors();
                $this->insert();
            }

        } else {
            redir_to('error');
        }
    }

    /**
     * Check if data are ready to be safe in database
     * @param $input - validation class
     * @return bool
     */
    protected function _validate_input(&$input) {
        $name         = ucwords( $input->escape($_POST['name']) );
        $last_name    = ucwords( $input->escape($_POST['last_name']) );
        $city         = ($_POST['city'] != 0) ? $_POST['city'] : null;
        $mob1         = !empty( $_POST['mob1'] ) ? $input->check($_POST['mob1'], "Mobitel 1", array("digit" => true)) : "";
        $mob2         = !empty( $_POST['mob2'] ) ? $input->check($_POST['mob2'], "Mobitel 2", array("digit" => true)) : "";
        $home_tel     = !empty( $_POST['home_tel'] ) ? $input->check($_POST['home_tel'], "Kućni", array("digit" => true)) : "";
        $job_tel      = !empty( $_POST['job_tel'] ) ? $input->check($_POST['job_tel'], "Posao", array("digit" => true)) : "";
        $pic_contact  = "";
        $desc_contact = $input->escape($_POST['desc_contact']);

        $input->check($name, "Ime", array(
            "required" => true,
            "minlength" => 3
        ));

        // if something has been uploaded => set name of the file
        if($input->handle_upload(IMAGES.'contacts')) {
            $pic_contact = $input->upload_name();
            $input->check($pic_contact, "Picture", array(
                'maxlength' => 255
            ));
        } else {
            $pic_contact = "default.jpg";
        }

        $this->_contact_vals = array(
            $name, $last_name,
            $mob1, $mob2, $home_tel, $job_tel,
            $pic_contact, $desc_contact, $city
        );

        return !$input->has_errors();
    }

    /**
     * Save to the database
     * @return void
     */
    protected function _save_to_db() {
        if( !empty($this->_contact_vals) ) {
            list($name, $last_name, $mob1, $mob2, $home_tel, $job_tel, $pic_contact, $desc_contact, $city) = $this->_contact_vals;
            $this->model->insert_contact($name, $last_name, $mob1, $mob2, $home_tel, $job_tel, $pic_contact, $desc_contact, $city);
        }
    }

    public function logout() {
        Session::clean();
        Session::destroy();
        redir_to('main');
    }

    public function edit($id) {
        //pretty_print($this->model->edit_contact($id), "contact");
        //pretty_print($_POST, "post");
        if(FORM_SUBMIT == "POST" && isset($_POST['cancel_edit'])) {
            redir_to('contacts/view/'.(int)$id);
        } else {
            $this->_update($id);
        }
        $this->data(array(
            "contact" => $this->model->edit_contact($id),
            "cities" => $this->model->get_cities()
        ));
        $this->view->render('edit');
    }

    protected function _update($id) {
        if(FORM_SUBMIT == "POST" && isset($_POST['submit'])) {
            $input = new Input();
            // if these fields are empty, do not safe anything
            if( empty($_POST['mob1']) && empty($_POST['mob2']) && empty($_POST['home_tel']) && empty($_POST['job_tel']) ) {
                $this->view->data["succ_or_err"] = "failure";
                $this->data("errorMsg::Nema podataka za spremanje. Barem jedan broj mora biti unešen.");
                return;
            }

            if($this->_validate_input($input)) {
                $this->_update_to_db($id);
                Session::multi_set(array(
                    'succ_or_err' => 'success',
                    'action_message' => 'Promjene uspješno spremljene'
                ));
                redir_to('contacts/view/'.$id);

            } else { // display existing errors
                $this->data(array(
                    "succ_or_err" => "failure",
                    "errorMsg" => $input->get_formatted_errors(),
                    "contact" => $this->model->edit_contact($id),
                    "cities" => $this->model->get_cities()
                ));
                $this->view->render('edit');
            }

        }
    }

    /**
     * Save updated informations to the database
     * @return void
     */
    protected function _update_to_db($id) {
        if( !empty($this->_contact_vals) ) {
            list($name, $last_name, $mob1, $mob2, $home_tel, $job_tel, $pic_contact, $desc_contact, $city) = $this->_contact_vals;
            $this->model->update($id, $name, $last_name, $mob1, $mob2, $home_tel, $job_tel, $pic_contact, $desc_contact, $city);
        }
    }

    public function delete($id) {
        if( $this->model->delete_contact($id) ) {
            Session::multi_set(array(
                'succ_or_err' => 'success',
                'action_message' => 'Kontakt uspješno izbrisan',
            ));
            redir_to('contacts');
            
        } else {
            Session::multi_set(array(
                'succ_or_err' => 'failure',
                'action_message' => 'Došlo je do pogreške. Molimo Vas, pokušajte ponovo.',
            ));
            redir_to('contacts/view/'.$id);
        }
    }

    public function test() {
        
    }

} 
<?php

class Error extends Controller {

    protected $_message = "It's seems requested page doesn't exist...";

	public function index() {
		$this->view->title = "Error";
        $this->view->data["message"] = $this->_message;
        $this->view->data["home_link"] = $this->_home_link();
        $this->view->render('error');
	}

    protected function _home_link() {
        return '<a class="back-link" href="'.BASE_URL.DEFAULT_CONTROLLER.'">&xlarr; Contacts</a>';
    }



}
<?php

class Main extends Controller {

	public function __construct() {
		parent::__construct();
		if( Session::get('id_user') ) {
			redir_to("contacts");
		}
		$this->_load_model('main');
	}

	public function index() {
		$this->title("Dobrodošli");
		$this->data("sign_up::Sign up");
		$this->view->render("main");
		//echo password_hash("stiiv85", PASSWORD_BCRYPT); // user id = 1
		//echo password_hash("kreso", PASSWORD_BCRYPT); // user id = 2
	}

	// LOG IN
	public function login() {

		if(FORM_SUBMIT == "POST") {
			$input = new Input();
			$username = trim($_POST['username']);
			$password = trim($_POST['password']);

			$username = $input->escape($username);
			$password = $input->escape($password);

			// check if the username exists in database
			$user = $this->model->user;
			if($user->get_password($username)) {
				$hashed_password = $user->get_password($username);
				//var_dump($hashed_password);
				$this->_password_check($input, $password, $hashed_password);
				
			} else { // username doesn't exists
				$this->_errorMsg($input);
				$this->_incorrect_user_or_pass($input);
			}
			
		} else { // forbid access 
			redir_to('error');
		}
	}

	protected function _password_check($input, $password, $hashed_password) {
		$user = $this->model->user;

		if( password_verify($password, $hashed_password) && !$input->has_errors() ) {
			//var_dump($user->get_id());
			Session::set("id_user", $user->get_id());
			redir_to('contacts');
		} else { // password is not correct
			$this->_errorMsg($input);
			$this->_incorrect_user_or_pass($input);
		}
	}

	protected function _errorMsg($input) {
		$error = "Vaše korisničko ime ili lozinka nisu točni. Molimo Vas, pokušajte ponovno";
		return $input->errorMsg["login_error"] = $error;
	}

	protected function _incorrect_user_or_pass($input) {
		$this->data("sign_up::Sign up");
		$this->data("succ_or_err::failure");
		$this->data("errorMsg::".$input->errorMsg["login_error"]);
		$this->view->render('main');
	}

	// SIGN UP
	public function register() {
		if(FORM_SUBMIT == "POST") {
			$input = new Input();

			$username   = $input->check($_POST['username'], "Username", array(
				'required' => true,
				'minlength' => 3,
				'maxlength' => 20
			));

			$password   = $input->check($_POST['password'], "Password", array(
				'required' => true,
				'minlength' => 5
			));
			$hashed_password = $input->hash($password);

			$password_again = $input->check($_POST['password_again'], "Retype Password", array(
				'match' => 'password'
			));

			$first_name = $input->check($_POST['first_name'], "Ime", array(
				'required' => true,
			));
			$first_name = ucwords($first_name);

			$last_name  = $input->check($_POST['last_name'], "Prezime", array(
				'required' => true
			));
			$last_name  = ucwords($last_name);

			$email      = $input->check($_POST['email'], "E-mail", array(
				'required' => true,
				'email' => true
			));
			
			if( $this->_is_ready_for_db($input) ) {

				if( $this->model->insert_new_user($username, $hashed_password, $first_name, $last_name, $email) ) {
					unset($_POST);
					$this->data("success_message::Registracija uspješna");
					$this->view->render('success');
					redir_sec('main');
				} else { // something went wrong
					$input->errorMsg["unknown_error"] = "Došlo je do greške. Molimo Vas, pokušajte ponovno";
					$this->data("succ_or_err::failure");
					$this->data("errorMsg::".$input->errorMsg["unknown_error"]);
				}

			}

		} else { // no post request
			redir_to('error');
		}
	}

	protected function _is_ready_for_db($input) {
		if( !$input->has_errors() ) {
			return true;
		}
		// otherwise display errors
		$this->data(array(
			'succ_or_err' => 'failure',
			'errorMsg' => $input->get_formatted_errors(),
			'sign_up' => 'Sign up'
		));
		$this->view->render('main');
		return false;
	}

}
<?php

class Test extends Controller {
	
	public function index() {
		$this->view->title = 'Test title';
		$this->view->data['subtitle'] = 'Test subtitle';
		$this->view->data['body'] = 'Hello, in order to begin, we need to test this.';
		$this->view->render('test_view');
	}

}

<?php

class Input
{
/****************************************************************************
 *
 *                              UPLOAD HANDLER
 *
 ****************************************************************************/

    // upload information
    private $_upload_name,
			$_upload_type,
			$_upload_size,
			$_upload_temp,
			$_upload_error,
			$_types = array('jpeg', 'JPG', 'jpg', 'pjpeg', 'gif', 'x-png', 'png'),
			$_allowedTypes = array();

    // 1 MB = 1048576 B
    const MB = 1048576;

    // give upload_error meaning ( copied from PHP Manual => upload error messages )
    protected $_upload_errors = array(
        0 => 'No error',
        1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini',
        2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form',
        3 => 'The uploaded file was only partially uploaded',
        4 => 'No file was uploaded',
        6 => 'Missing a temporary folder. Introduced in PHP 5.0.3',
        7 => 'Failed to write file to disk. Introduced in PHP 5.1.0.',
        8 => 'A PHP extension stopped the file upload'
    );
			
	public $errorMsg = array();

    public function __construct() {
        $this->_allowedTypes = add_to_array_elements('image/', $this->_types);
    }

    /**
     * Check if anything has been uploaded
     * @return bool
     */
    public function is_file_uploaded() {
        return ( $this->upload_error() != UPLOAD_ERR_NO_FILE ) ? true : false;
    }

	/**
	 * Desc: checks if the uploaded file is allowed type
	 * @return true or false
	 */
	public function is_valid_upload_type() {
		
		if($this->upload_type() == null) {
			return false;
		}
		elseif(!in_array($this->upload_type(), $this->_allowedTypes)) {
			$this->errorMsg["file_type"] =
                'Datoteka nije dozvoljenog formata! Dozvoljeni format: '.implode(',', $this->_types);
			return false;
		}
		else {
			return true;
		}
	}

    /**
     * Determine whether the uploaded file exceeds max file size in php.ini or form
     * @return boolean (true if max_upload_size is ok, false otherwise )
     */
    public function is_max_upload_size() {
        if( $this->upload_error() == UPLOAD_ERR_INI_SIZE || $this->upload_error() == UPLOAD_ERR_FORM_SIZE ) {
            $this->errorMsg["max_upload_size"] =
                "Datoteka je prevelika, najveća dopuštena veličina : "
                .$this->byte_to_mb( $this->form_max_upload_size() )." MB";
            return false;
        }
        return true;
    }

    /**
     * Value of max_file_size in bytes
     * @return int (value of form max_file_size, 0 otherwise)
     */
    public function form_max_upload_size() {
        return (int)( isset($_REQUEST["MAX_FILE_SIZE"]) && is_numeric($_REQUEST["MAX_FILE_SIZE"]) ) ? $_REQUEST["MAX_FILE_SIZE"] : 0;
    }

    /**
     * Convert bytes into Megabytes
     * @param bool $bytes
     * @return int
     */
    public function byte_to_mb($bytes = false) {
        if(is_numeric($bytes) && $bytes) {
            return (int)$bytes / self::MB;
        }
        return 0;
    }

    /**
     * Convert Megabytes into bytes
     * @param bool $mb
     * @return int
     */
    public function mb_to_byte($mb = false) {
        if( is_numeric($mb) ) {
            return (int)$mb * self::MB;
        }
        return 0;
    }
	
	/**
	 * Desc: if the file exists in images folder
	 * @param string : directory where the searched file is placed
	 * @return true or false
	 */
	public function does_file_exist($path_dir) {
		if(file_exists($path_dir.$this->upload_name())) {
			$this->errorMsg["file_exists"] = 'Datoteka <strong>'.$this->upload_name().'</strong> već postoji';
			return true;
		}
		return false;
	}
	
	/**
	 * Desc: handle upload
     * @param string $dir - directory to permanently store uploaded file
     * @return boolean
	 */
	public function handle_upload($stored_dir) {
        if( is_string($stored_dir) ) {

            if( $this->is_valid_upload_type()
                && $this->is_max_upload_size()
                && $this->is_file_uploaded()
                && empty($this->errorMsg)
            ) {
                if( move_uploaded_file($this->upload_temp(), $stored_dir.DS.$this->upload_name()) ) {
                    return true;
                } else {
                    $this->errorMsg["upload_error"] = $this->upload_err_message();
                    return false;
                }
            }

        }
        return false;
	}

    /**
     * Value of name attribute in form
     * @return mixed
     */
    public function upload_file_form_name() {
        return array_keys($_FILES)[0];
    }
	
	/**
	 * Setting up class properties
	 */
	public function upload_name() {
		return $this->_upload_name = $_FILES[$this->upload_file_form_name()]['name'];
	}
	
	public function upload_size() {
		return $this->_upload_size = $_FILES[$this->upload_file_form_name()]['size'];
	}
	
	public function upload_type() {
		return $this->_upload_type = $_FILES[$this->upload_file_form_name()]['type'];
	}
	
	public function upload_temp() {
		return $this->_upload_temp = $_FILES[$this->upload_file_form_name()]['tmp_name'];
	}
	
	public function upload_error() {
		return $this->_upload_error = $_FILES[$this->upload_file_form_name()]['error'];
	}
	
	public function error() {
		return $this->_error;
	}

    /**
     * Display appropriate upload error status as message
     * @return string
     */
    public function upload_err_message() {
        return $this->_upload_errors[$this->upload_error()];
    }

    /**
     * Display update information
     * @return string
     */
    public function upload_info() {
        $html  = "<hr />";
        $html .= "FILE FORM NAME: ".$this->upload_file_form_name()."<br />";
        $html .= "FILE NAME: ".$this->upload_name()."<br />";
        $html .= "FILE SIZE: ".$this->upload_size()." B<br />";
        $html .= "FILE TYPE: ".$this->upload_type()."<br />";
        $html .= "FILE TEMP DIRECTORY: ".$this->upload_temp()."<br />";
        $html .= "FILE ERROR: ".$this->upload_err_message()."<br />";
        $html .= "<hr />";
        return $html;
    }



/*******  __toString() **************/
    public function __toString() {
        return $this->upload_info();
    }



/****************************************************************************
 *
 *                              VALIDATION HANDLER
 *
 ****************************************************************************/

    // Array of available rules
    protected $_allowed_rules = array(
        'required', 'email', 'minlength', 'maxlength', 'select', 'digit',
        'match'
    );

    /**
     * Filter given string
     * @param string $input
     * @return mixed|string
     */
    public function escape($input) {
        return is_string($input) ? filter_var($input, FILTER_SANITIZE_STRING) : "";
    }

    /**
     * Hash given string
     * @param string $string
     * @return string
     */
    public function hash($string) {
        return password_hash($string, PASSWORD_BCRYPT);
    }

    /**
     * First and main function.
     * @param string $input - Input value
     * @param string $field_name - Name to give for the field error
     * @param string/array $rules
     * @return $this
     */
    public function check($input, $field_name, $rules) {

        if( is_string($input) || is_numeric($input) ) {

            $input = trim( $input );

            if( is_array($rules) ) {

                $rule_array = array_keys($rules);
                // check if the set of rules exist in $this->_allowed_rules array
                if( $this->_rule_exists($rule_array) ) {
                    $this->_validate($input, $field_name, $rules);
                    $this->_input = $input;
                }

            } elseif( is_string($rules) ) {}
        }

        return $this->escape( trim($input) );

    } // end check

    /**
     * @param string $input - Input value
     * @param string $field_name - Name to give for the field error
     * @param array $rules - rules to check against
     * @return void
     */
    protected function _validate($input, $field_name, $rules) {
        $encoding = 'UTF-8';
        // get form name="" values
        $request_keys = array_keys($_REQUEST);

        foreach($rules as $rule => $satisfier) {

            switch($rule) {
                case 'required':
                    if( empty($input) ) {
                        $this->errorMsg[$field_name][] = 'Required';
                        return;
                    }
                    break;

                case 'email':
                    ( !filter_var($input, FILTER_VALIDATE_EMAIL) ) ? $this->errorMsg[$field_name][] = 'Not valid email' : null;
                    break;

                case 'minlength':
                    (mb_strlen($input, $encoding) <= $satisfier) ? 
                        $this->errorMsg[$field_name][] = "Too short. At least {$satisfier} characters required" : null;
                    break;

                case 'maxlength':
                    (mb_strlen($input, $encoding) >= $satisfier) ? 
                        $this->errorMsg[$field_name][] = "Too long. Maximum {$satisfier} characters" : null;
                    break;

                case 'select':
                    ($input < 1 || $input == null) ? $this->errorMsg[$field_name][] = 'Not selected' : null;
                    break;

                case 'digit':
                    ( !is_numeric($input) ) ? $this->errorMsg[$field_name][] = 'Must contain only digits' : null;
                    break;

                case 'match':
                    // check if the given satisfier is correct
                    if( !in_array($satisfier, $request_keys) ) {
                        $this->errorMsg[$field_name][] = "Satisfier '{$satisfier}' does not match any field";
                        return;
                    }

                    if( $_REQUEST[$satisfier] != $input) {
                        $this->errorMsg[$field_name][] = 'No match';
                    }
                    break;
            }
        }
    }

    /**
     * Check if input rule exists in $this->_allowed_rules;
     * @param array $array
     * @return boolean
     */
    protected function _rule_exists($array) {
        if(is_array($array)) {
            foreach($array as $value) {
                return in_array($value, $this->_allowed_rules);
            }
        }
        return false;
    }

    public function has_errors() {
        return !empty($this->errorMsg);
    }

    public function get_errors() {
        return $this->has_errors() ? $this->errorMsg : null;
    }

    /**
     * Get errors in formatted unordered list form
     * @return null|string
     */
    public function get_formatted_errors() {

        if($this->has_errors()) {

            $html = '<ul class="validate-error">';

            foreach($this->errorMsg as $title_group => $group) {

                $html .= '<li>';
                $html .= $title_group.':';
                    $html .= '<ul>';

                // if group array has more than one value, iterate through it
                if(count($group) > 1) {
                    foreach($group as $grouped_error) {
                        $html .= '<li>'.$grouped_error.'</li>';
                    }
                } else {
                    $html .= '<li>'.$group[0].'</li>';
                }

                    $html .= '</ul>';
                $html .= '</li>';
            }
            $html .= '</ul>';

            return $html;
        }
        return null;

    }
}
<?php

class Pagination {

    public $current_page,
           $per_page,
           $total;

    public function __construct($current_page, $per_page, $total) {
        $this->current_page = (int)$current_page;
        $this->per_page     = (int)$per_page;
        $this->total        = (int)$total;
    }

    /**
     * Check whether pagination is needed or not - if the per_page is less or equal to total = pagination not needed
     * @return bool
     */
    public function needs_pagination() {
        return ( isset($this->per_page) && ($this->per_page >= $this->total) ) ? false : true;
    }

    public function total_pages() {
        return ceil($this->total / $this->per_page);
    }

    public function offset() {
        // Assuming 20 items per page
        // page 1 has an offset of 0  (1-1) * 20
        // page 2 has an offset of 1  (2-1) * 20
        //      page 2 starts with item 21
        return ($this->current_page -1) * $this->per_page;
    }

    public function prev_page() {
        return $this->current_page - 1;
    }

    public function next_page() {
        return $this->current_page + 1;
    }

    public function has_prev_page() {
        return ($this->prev_page() >= 1);
    }

    public function has_next_page() {
        return ($this->next_page() <= $this->total_pages());
    }

} 
<?php

class Session {

	public static function init() {
		session_start();
	}

	public static function set($key, $value) {
		return $_SESSION[$key] = $value;
	}

	public static function multi_set(array $array) {
		foreach($array as $key => $value) {
			self::set($key, $value);
		}
	}

	public static function get($key) {
		return isset($_SESSION[$key]) ? $_SESSION[$key] : '' ;
	}

	public static function view() {
		pretty_print($_SESSION, "SESSION");
	}

	public static function clean() {
		$_SESSION = array();
	}

	public static function destroy() {
		session_destroy();
	}

}

Session::init();
<?php

class User {

	protected $_db;

	protected $_id, 
			  $_name,
			  $_password, 
			  $_table_name;

	public function __construct($db, $user_table_name = "users") {
		$this->_db = $db;
		$this->_table_name = $user_table_name;
	}

	/**
	* Get password from database and set $this->_name and $this->_password
	* @param string $username - username to get password from
	* @return mixed (string or false on failure)
	*/
	public function get_password($username) {
		$sql = "SELECT password FROM {$this->_table_name} WHERE username = ? LIMIT 1";
		$pass_obj = $this->_db->query($sql, array($username))->getResults();
		if($pass_obj) {
			$password = $pass_obj[0]->password;
			// set username
			$this->_name = $username;
			// set passwowrd
			$this->_password = $password;
			return $password;
		}
		return false;
	}

	public function get_id() {
		$sql = "
			SELECT ID FROM {$this->_table_name}
			WHERE username = ? 
			AND password = ? 
			LIMIT 1
		";
		$id_obj = $this->_db->query($sql, array($this->_name, $this->_password))
					   ->getResults();
		return (int) $id_obj[0]->ID;
	}

	/**
	* Check if the name has been set
	* @return boolean
	*/
	public function is_name_set() {
		return isset($this->_name) ? true : false;
	}

	/**
	* Set user name
	* @param string $username
	* @return void
	*/
	public function set_name($username) {
		$this->_name = $username;
	}

}
<?php

/****************************
 *                          *
 * DATABASE CONFIGURATION   *
 *                          *
 ****************************/

define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASS", "granaroot");
define("DB_NAME", "contact_app");

/*************************
 *                       *
 * DEFAULT CONTROLLER    *
 *                       *
 *************************/
$controller = "main";


/**************************
 *                        *
 * PATHS                  *
 *                        *
 **************************/

// general
define("DS", DIRECTORY_SEPARATOR);
define("BASE_URL", str_replace('index.php', '', $_SERVER["PHP_SELF"]));

define("CONTROLLERS", "controllers".DS);
define("MODELS", "models".DS);
define("VIEWS", "views".DS);
define("INCLUDES", "includes".DS);
//TEMPLATES
define("TEMPLATES", "templates".DS);
define("HEADER", "public".DS.TEMPLATES."header.php");
define("FOOTER", "public".DS.TEMPLATES."footer.php");
//HTML <head> paths
define("CSS", "public".DS."css".DS);
define("JS", "public".DS."js".DS);
define("IMAGES", "public".DS."images".DS);




/**************************
 *                        *
 * CONSTANTS              *
 *                        *
 **************************/

// SUBMIT FORM
define("FORM_SUBMIT", $_SERVER['REQUEST_METHOD']);
define( "DEFAULT_CONTROLLER", strtolower($controller) );

<?php

function date_trans($trans) {
    
    $trans = substr($trans, 0, 10);
    $date_trans = explode('-', $trans);
    return $date_trans[2].'.'.$date_trans[1].'.'.$date_trans[0].'.';
}

/**
 * @Desc: add given word into array element
 * @param string - word to add
 * @param array - array to add given word to
 * return mixed
 */
function add_to_array_elements($word, $type) {
    
    if(is_array($type)) {
        $i = 0;
        $elements = '';	
        foreach($type as $element) {
            $i++;
            //check if an element is a last in array (if it is, remove comma)
            if($i >= count($type)) {
                $elements .= $word.$element;
            }
            else {
                $elements .= $word.$element.',';
            }
        }
        return explode(',', $elements);
    }
    return false;
}

function pretty_print($val, $name = "Name", $color = "darkgreen") {
    echo "<pre style=\"color: {$color};\"><h3> {$name} = ", print_r($val, true), '</h3></pre>';
}

/**
 * Redirect to the given page
 * @param $location
 * @return void
 */
function redir_to($location) {
    header("Location: ".BASE_URL.$location);
}

/**
 * Redirect to the given page in given time
 * @param $location
 * @param [, int $time ]
 * @return void
 */
function redir_sec($location, $time = 3) {
    header("Refresh: {$time}; url=".BASE_URL.$location);
}
<?php

// automatically include all files inside folder
foreach(glob("includes/*.php") as $file) {
    require $file;
}

function __autoload($class) {

	// directories to include __autoload
	$dirs = array(
		"libs".DS,
		"helpers".DS
	);

	foreach($dirs as $dir) {
		$dir_class = $dir.$class.".php";

		if(file_exists($dir_class)) {
			require_once($dir_class);
			return;
		}
	}
}

$app = new Bootstrap();
<?php

class Bootstrap {

    private $_url;
    public $controller;

    public function __construct() {

        $this->_url = (isset($_GET['url'])) ? $_GET['url'] : null;
        $this->_url = rtrim($this->_url, "/");
        $this->_url = explode("/", $this->_url);
        //print_r($this->_url);
        if(isset($this->_url[0]) && file_exists(CONTROLLERS.$this->_url[0]."_controller.php")) {
            require_once CONTROLLERS.$this->_url[0]."_controller.php";
            $controller_name = ucfirst($this->_url[0]);
            $this->controller = new $controller_name;

        } else {

            if(empty($this->_url[0])) {
                $this->_defaultController();
            } else {
                $this->_error();
            }
        }
        $this->_method_to_load();
    }

    //default controller
    private function _defaultController() {

        require_once CONTROLLERS.DEFAULT_CONTROLLER."_controller.php";
        $controller = ucfirst(DEFAULT_CONTROLLER);
        $this->controller = new $controller();
    }

    //error controller
    private function _error() {
        require_once CONTROLLERS."error_controller.php";
        header("Location: ".BASE_URL."error");
        $this->controller = new Error();
        return false;
    }

    // determine which method to load
    private function _method_to_load() {

        //if(count($this->_url) > 3) {
        //    $this->_error();
        //}

        if(isset($this->_url[1]) && method_exists($this->controller, $this->_url[1])) {
            $method = strtolower($this->_url[1]);

            if(isset($this->_url[2]) && !empty($this->_url[2])) {
                $param = $this->_url[2];
                $this->controller->$method($param);
            } else {
                $this->controller->$method();
            }

        } elseif(empty($this->_url[1])) {
            $this->controller->index();

        } else {
            $this->_error();
        }
    }

}
<?php

class Controller {

    public $view, $model;
    // variable to set with Input() helper class
    protected $_input;

    public function __construct() {
        $this->view = new View();
    }

    //default method
    public function index() {}

    protected function _load_model($model) {
        require_once MODELS.strtolower($model)."_model.php";

        $model = ucfirst($model)."_Model";
        $this->model = new $model();
    }

    /**
     * Abstract passing title in $this->view->data->title
     * @param string=variable/value separator '::' | array $view_data
     * @return mixed
     */
    public function title($title) {
        return $this->view->title = $title;
    }

    /**
     * Abstract passing key/value pairs in $this->view->data array
     * @param string=variable/value separator '::' | array $view_data
     * @return mixed
     */
    public function data($view_data) {

        if( is_string($view_data) ) {
            // check if the '::' character exists in string
            if( strpos($view_data, "::") !== false ) {
                $var_val = explode('::', $view_data);
                $var = $var_val[0];
                $val = $var_val[1];
                return $this->view->data[$var] = $val;
            }
            return null;

        } elseif( is_array($view_data) ) {
            foreach($view_data as $key => $value) {
                $this->view->data[$key] = $value;
            }
            return $this->view->data;
        } else {
            return false;
        }
    }      

}
<?php

class DB
{
	private static $_instance = NULL;
	private $_dbc,
			$_query,
			$_PDOparam,
			$_error = false,
			$_insert,
			$_edit,
			$_delete,
			$_count = 0,
			$_result;
			
	private $_time_key,
			$_time_value;
	public	$time_true = false;
	
	
	private function __construct()
	{
		
		try
		{
			$this->_dbc = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS);
			$this->_dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$this->_dbc->query("SET names 'utf8'");
		}
		catch(PDOException $e)
		{
			die($e->getMessage());
		}
	}
	
	public static function getInstance()
	{
		if(!isset(self::$_instance))
		{
			self::$_instance = new DB();
		}
		return self::$_instance;
	}
	
	/**
	 * Desc : abstract PDO prepare statement
	 * 
	 * @param : sql string
	 * @param : [, array $params - parameters of sql query in array ]
	 *
	 * @return : this object to allow chain other methods or false ($this->_error = true)
	 */
	public function query($sql, $params = array())
	{
		$this->_error = false;
		
		if($this->_query = $this->_dbc->prepare($sql))
		{
			$i = 1;
			
			if(count($params))
			{
				foreach($params as $param)
				{	
					$this->_query->bindValue($i, $param);
					//echo $i.' - '.$param.' || ';
					$i++;
				}
			}
			
			if($this->_query->execute())
			{
				if(!$this->_insert && !$this->_delete && !$this->_edit)
				{
					$this->_result = $this->_query->fetchAll(PDO::FETCH_OBJ); //echo "<pre>",var_dump($this->_result),"</pre>";
				}
				
				$this->_count = $this->_query->rowCount();
			}
			else
			{
				$this->_error = true;
			}
		}
		
		return $this;
	}
	
	/**
	 * Desc : insert into database
	 * @param : string $table
	 * @param : array $fields
	 * @param : [, array $time required if you need save data without prepering query ]
	 * @return : true or false
	 */
	public function insert($table, $fields = array(), $time = array())
	{
		if(count($fields))
		{	
			$this->_insert = false;
			$keys = array_keys($fields); //print_r($keys);
			$countf = count($fields);
			$values = '';
			$i = 1;
			
			foreach($fields as $field)
			{	
				$values .= '?';
				if($i < $countf)
				{
					$values .= ', ';
				}
				
				$i++;
			}
			
			$explodeVal = array();
			if(count($time))
			{
				$this->time_true = true;
				$explodeVal = explode(', ', $values);
				//array_pop($explodeVal);
				$this->_time_key = '';
				$this->_time_value = '';
				
				foreach($time as $kt => $vt)
				{
					if($vt != 'NOW()')
					{
						$vt = 'NOW()';
					}
					$this->_time_value .= $vt;
					$this->_time_key .= $kt;
					
					$keys[] = $this->_time_key;
					$explodeVal[] = $this->_time_value;
					$values = implode(', ', $explodeVal);
				}
				//echo '<pre>',print_r($explodeVal),'</pre>';
			}
			
			$this->_insert = true;
			$sql = "INSERT INTO {$table} (`".implode('`, `', $keys)."`) VALUES(".$values.")";
			//echo '<pre>',print_r($fields),'</pre>';
			//echo $sql; //die();
			if(!$this->query($sql, $fields)->error())
			{
				return true;
			}
		}
		return false;
	}

	/**
	 * Desc : edit table
	 * @param : string $table
	 * @param : int $id
	 * @param : array $fields
	 * @return : true or false
	 */
	public function update($table, $id, $fields = array()) {
		$id = (int)$id;

		if(count($fields)) {
			
			$this->_edit = false;
			$keys = array_keys($fields); //print_r($keys);
			$countf = count($fields);
			$i = 1;
			
			$this->_edit = true;
			$sql  = "UPDATE {$table} SET ";

			foreach($keys as $key) {
				// make sure that there is no comma after last question mark
				$value = ($i < $countf) ? '?, ' : '?';
				$sql .= "{$key} = {$value} ";
				$i++;
			}

			$sql .= "WHERE id = {$id} LIMIT 1";
			if(!$this->query($sql, $fields)->error()) {
				return true;
			}
		}
		return false;
	}
	
	/**
	 * Desc : delete from database
	 * @param : string $table
	 * @param : array $fields
	 * @return : true or false
	 */
	public function delete($table, $fields = array())
	{
		if(count($fields))
		{
			$this->_delete = false;
			$keys = array_keys($fields); //print_r($keys);
			$countf = count($fields);
			$values = '';
			$i = 1;
			
			foreach($fields as $field)
			{	
				$values .= '?';
				if($i < $countf)
				{
					$values .= ', ';
				}
				$i++;
			}
			
			$this->_delete = true;
			$sql = "DELETE FROM {$table} WHERE (`".implode('`, `', $keys)."`) = (".$values.")";
			if(!$this->query($sql, $fields)->error())
			{
				return true;
			}
		}
		return false;
	}
	
	/**
	 * @return : attribute $_error status (tue or false)
	 */
	public function error()
	{
		return $this->_error;
	}
	
	/**
	 * @return : attribute $_result status
	 */
	public function getResults()
	{
		return $this->_result;
	}
	
	public function countResults()
	{
		return $this->_count;
	}

}
<?php

class Model {
    
    protected $_db;
    
    public function __construct() {
        $this->_db = DB::getInstance();
    }

    /**
     * Count how many results has in given table
     * @param $table
     * @return mixed
     */
    public function count_table($table) {
        $sql = "SELECT COUNT(*) AS count FROM {$table} ";
        $results = $this->_db->query($sql)->getResults();
        return (int)$results[0]->count;
    }

    /**
     * @return int - number of matched results
     */
    public function countRes() {
        return $this->_db->countResults();
    }

    /**
     * Check whether there is results or not
     * @return bool
     * @todo requires additional checks
     */
    /*public function has_results() {
        return ($this->_db->getResults() > 0) ? true : false;
    }*/
}
<?php

class View {
    
    public $title, $data = array();

    public function __construct() {

        if(!isset($this->title)) {
            $title = explode('/', $_SERVER['REQUEST_URI']);
            $title = $title[2];

            if( empty($title) ) {
                $title = DEFAULT_CONTROLLER;
            }
            $this->title = ucfirst( $title );
        }
    }
    
    /**
     * Desc: include template file
     * @param string $template
     * @param [, true if is no requirement for templates header and footer ]
     * @return void
     */
    public function render($template, $noInclude = false) {
        if( isset($this->data) && !empty($this->data) ) {
            extract($this->data);
            
            if($noInclude) {
                require_once VIEWS.$template.".php";
            } else {
                require_once HEADER;
                require_once VIEWS.$template.".php";
                require_once FOOTER;
            }
        }
    }

    /**
     * Display variable if set
     * @param $var
     * @return string
     */
    public function var_check(&$var) {
        return isset($var) ? htmlspecialchars($var,ENT_QUOTES,'UTF-8') : '';
        //I put htmlspecialchars into the var_check to avoid the XSS injection.
    }
    
}
<?php


class Contact_Model extends Model {

    public $id_user;
    // initialize user object
    public $user;

    public function __construct() {
        parent::__construct();
        $this->user = new User($this->_db);
        $this->id_user = Session::get('id_user');
    }

    public function get_username() {
        $sql = "SELECT username from users WHERE ID = ?";
        $user_obj = $this->_db->query($sql, array($this->id_user))->getResults();
        return $user_obj[0]->username;
    }

    public function search_query($query) {
        $param = "%{$query}%";
        $sql  = "SELECT ";
        $sql .= "id as ID, ime, prezime, mob1, mob2, kucni, posao ";
        $sql .= "FROM contacts ";
        $sql .= "WHERE ime LIKE ? ";
        return $this->_db->query($sql, array($param))->getResults();
    }

    public function is_search($query) {
        $search = $this->search_query($query);
        return !empty( $search );
    }

    public function count_table($table) {
        $sql  = "SELECT COUNT(*) AS count FROM {$table} ";
        $sql .= "WHERE id_user = ? ";
        $results = $this->_db->query($sql, array($this->id_user))->getResults();
        return (int)$results[0]->count;
    }

    public function total_contacts() {
        return $this->count_table('contacts');
    }

    public function get_cities() {
        return $this->_db->query("SELECT id, ime FROM gradovi ORDER BY ime")->getResults();
    }


    public function insert_contact($ime, $prezime, $mob1, $mob2, $kucni, $posao, $slika, $opis, $id_grad) {
        $this->_db->insert('contacts', array(
            'id_user' => $this->id_user,
            'ime' => $ime,
            'prezime' => $prezime,
            'mob1' => $mob1,
            'mob2' => $mob2,
            'kucni' => $kucni,
            'posao' => $posao,
            'slika' => $slika,
            'opis' => $opis,
            'id_grad' => $id_grad
        ));

        return $this->_db->countResults();
    }

    /**
     * Get all contacts
     * @param null $limit - optional
     * @param null $offset - optional
     * @return mixed
     */
    public function get_all_contacts($limit = null, $offset = null) {
        $sql  = "SELECT ";
        $sql .= "c.id as ID, c.ime, c.prezime, c.mob1, c.mob2, c.kucni, c.posao, c.slika, c.opis, ";
        $sql .= "g.ime AS ime_grada ";
        $sql .= "FROM contacts AS c ";
        $sql .= "LEFT OUTER JOIN gradovi AS g ";
        $sql .= "ON g.id = c.id_grad ";
        $sql .= "WHERE c.id_user = ? ";
        $sql .= "ORDER BY c.ime, c.prezime ";
        $sql .= ( !is_null($limit) ) ? "LIMIT ".(int)$limit : null;
        $sql .= ( !is_null($offset) ) ? " OFFSET ".(int)$offset : null;
        return $this->_db->query($sql, array($this->id_user))->getResults();
    }

    public function has_results() {
        return ($this->count_table('contacts') > 0);
    }

    public function view_contact($id) {
        $sql  = "SELECT ";
        $sql .= "c.id as ID, c.ime, c.prezime, c.mob1, c.mob2, c.kucni, c.posao, c.slika, c.opis, ";
        $sql .= "g.id AS id_grada, g.ime AS ime_grada ";
        $sql .= "FROM contacts AS c ";
        $sql .= "LEFT OUTER JOIN gradovi AS g ";
        $sql .= "ON g.id = c.id_grad ";
        $sql .= "WHERE c.id = ? ";
        $sql .= "AND c.id_user = ? ";
        $sql .= "LIMIT 1 ";
        return $this->_db->query($sql, array($id, $this->id_user))->getResults()[0];
    }

    public function edit_contact($id) {
        return $this->view_contact($id);
    }

    public function update($id, $ime, $prezime, $mob1, $mob2, $kucni, $posao, $slika, $opis, $id_grad) {

        $this->_db->update('contacts', $id, array(
            'id_user' => $this->id_user,
            'ime' => $ime,
            'prezime' => $prezime,
            'mob1' => $mob1,
            'mob2' => $mob2,
            'kucni' => $kucni,
            'posao' => $posao,
            'slika' => $slika,
            'opis' => $opis,
            'id_grad' => $id_grad
        ));
        return ($this->_db->countResults()) ? true : false;
    }

    public function delete_contact($id) {
        $this->_db->delete('contacts', array('id' => $id));
        return ($this->_db->countResults()) ? true : false;
    }

} 
<?php

class Main_Model extends Model {

	public $user;

	public function __construct() {
		parent::__construct();
		$this->user = new User($this->_db);
	}

	public function insert_new_user($username, $password, $first_name, $last_name, $email) {
		$this->_db->insert('users', array(
			'username' => $username,
			'password' => $password,
			'first_name' => $first_name,
			'last_name' => $last_name,
			'email' => $email
		));

		return ($this->_db->countResults() > 0) ? true : false;
	}

}
@charset "UTF-8";
/*****************************************
 *
 * Stiiv 2014
 * 
 * @colors:
 *  light blue : #A5C2E8;
 *
 *****************************************/
*{ padding: 0; margin: 0; }

 /* solve backward compatibility html5 tags issues */
 article, aside, footer, header, main, nav, section
 { display: block; }

  /** prevent focus outline on chrome **/
 input, select, textarea { outline: none; margin: 0 0 2px 2px; }

 /* remove spacing between table th, td, tr */
 table {
    border-collapse: collapse;
    border-spacing: 0;
 }

 body {
     font-family: Helvetica, Arial, sans-serif;
     min-width: 200px;
     width: 100%;
     height: 100%;
 }

 .clear { clear: both; }
 .bold { font-weight: bold; }
 .position-relative { position: relative; }
 .close {
    display: block;
    cursor: pointer;
    padding: .1% .3em;
    margin: .1em .3em;
    font-size: .8em;
    position: absolute;
    top: .1em;
    right: 0;
 }
 .close:hover { background: #fff; }

 div#wrapper {
     min-width: 320px;
     width: 95%;
     max-width: 1024px;
     margin: 0 auto;
     -webkit-box-shadow: 2px 2px 8px #000000;
     -moz-box-shadow: 2px 2px 8px #000000;
     box-shadow: 2px 2px 8px #000000;
 }

 #header {
     color: #647587;
     background: #ccc;
     padding: 2% 3%;
 }
  #header a {
    display: inline-block;
    text-decoration: none;
    color: #647587;
 }

 #main-menu {
     background: #647587;
     padding: 1% 3%;
 }

 /* LOG IN FORM */

 #main-menu > #login-form { color: #ccc; }
 #main-menu > #login-form label {
    display: inline-block;
 }
 #main-menu > #login-form input {
    margin: .1em;
 }
 #main-menu > #login-form input[type="submit"] {
    color: #fff;
    background: #E6B26A;
    width: 7em;
 }
  #main-menu > #login-form input[type="submit"]:hover {
    background: #E3C7A1;
 }

#main-menu ul {
    list-style: none;
    position: relative;
}
#main-menu ul li {
    float: left;
    margin: .3em .5em;
}
#main-menu ul li > a {
    text-decoration: none;
    color: #ccc;
}
#main-menu ul li > a:hover {
    text-decoration: underline;
    color: #ccc;
}
/* USERMENU */
#main-menu ul li#username-menu {
    margin-right: 2%;
}
#main-menu ul li#username-menu a {
    display: block;
    width: 100%;
    background: #3D4752;
    padding: 6% 8%;
    position: relative;
    bottom: 0;
    left: 1%;
}
#main-menu ul li#username-menu ul {
    display: none;
    position: absolute;
    top: 2.4em;
    width: 7em;
    background: #3D4752;
}
#main-menu ul li#username-menu:hover ul {
    display: block;
}
#main-menu ul li#username-menu ul li  {
    
}
#main-menu ul li#username-menu ul li a {
    padding: 0;
    color: #ccc;
    text-decoration: none;
}
#main-menu ul li#username-menu ul li a:hover {
    text-decoration: underline;
}

#main-menu input {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    display: inline-block;
    width: 10em;
    height: 30px;
    margin-left: 3%;
    padding: .2em .5em;
    border: 0 solid #fff;
}
input#search-btn {
    width: 3em;
    margin-left: -10px;
    text-indent: -999px;
    background: url('../images/search_icon.png') center #fff no-repeat;
    background-size: 2em;
}
input#search-btn:hover {
    background: url('../images/search_icon.png') center #E3C7A1 no-repeat;
    background-size: 2em;
}

#content { background: #fff; }

section { width: 100%; padding: 2%; }

div.contacts {
    /*border: 1px solid red;*/
    width: 70%;
    margin-left: 5%;
}
div.contacts table {
    color: #647587;
    margin: 10px 0;
    border-top: .1em solid #000;
    border-bottom: .1em solid #000;
    min-width: 20%;
    width: 70%;
}
table td:first-child { color: #647587; }

div.contacts table tr:nth-child(even) { background: #fff; }
div.contacts table tr:nth-child(odd) { background: #E3E5E6; }
div.contacts table a.view-contact {
    color: #647587;
}
div.contacts table a.view-contact:hover {
    color: #000;
}
#view-contact-pic {
    width: 80%;
    border: .1em solid #647587;
    margin: 2%;
}

table.main-table td, th {
    padding: .2em;
}

form#insert-new-contact {
    width: 70%;
    margin-left: 5%;
}
form#insert-new-contact fieldset {
    border: .1em solid #E6B26A;
    padding: 5%;
}
form#insert-new-contact legend {
    font-size: 1.5em;
    color: #E6B26A;
}

form#insert-new-contact input, textarea, select {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 100%;
    max-width: 500px;
    padding: .2em .5em;
    border: .1em solid #E6B26A;
    background: #E3C7A1;
}
form#insert-new-contact textarea {
    min-width: 100%;
}
form#insert-new-contact input[type="submit"] {
    color: #fff;
    background: #E6B26A;
}
form#insert-new-contact input[type="submit"]:hover {
    background: #E3C7A1;
}

form#edit-contact input[type="text"], form#edit-contact textarea, form#edit-contact select {
    -moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    width: 100%;
    padding: .2em .5em;
    border: .1em solid #ccc;
    background: #fff;
}

/* Error or success message  */

ul.validate-error {
    list-style-type: none;
    list-style-position: inside;
    margin-left: -10%;
}
ul.validate-error li { font-weight: bold; }


ul.validate-error ul {
    list-style-type: circle;
    list-style-position: inside;
    margin-left: 10%;
}

/* page message for success or failure */

div.message {
    width: 63.5%;
    margin-left: 5%;
    padding: 3%;
    text-align: center;
    margin-bottom: 10px;
}
.edit-message {
    position: relative;
    left: -5.2%;
}
.success {
    color: #008000;
    border: .2em solid #006400;
    background: #BAF2B8;
}
.failure {
    color: #821111;
    border: .2em solid #821111;
    background: #E3C7A1;;
}

div.pagination {
    width: 70%;
    padding-left: 5%;
    text-align: center;
}
div.pagination span {
    display: inline-block;
    padding: 0 1%;
    margin: 0 .05em;
    color: #647587;
    border: .1em solid #647587;
}
div.pagination a, .back-link {
    display: inline-block;
    padding: 0 1%;
    margin: 0 .05em;
    color: #647587;
    background: #ccc;
    border: .1em solid #647587;
    text-decoration: none;
}
div.pagination a:hover, .back-link:hover {
    display: inline-block;
    padding: 0 1%;
    color: #647587;
    background: #ccc;
    border: .1em solid #ccc;
    text-decoration: none;
}

 #footer {
     text-align: center;
     color: #ccc;
     background: #647587;
     padding: 1% 3%;
 }
$(function() {
    $(".col2").hide().slideDown(600);
    
    var title = $('#title');
    var genre = $('#genre');
    var year = $('#year');
    var duration = $('#duration');
    
    function errorMsg(object, msg) {
        return $(object).addClass('error').html(msg);
    }
    
    function addErrorClass(object, errorSpan, message) {
        errorMsg(errorSpan, message);
        $(object).removeClass('current_input').addClass('error_input');
    }
    
    function rmErrorClass(object, errorSpan) {
        object.removeClass('error_input');
        errorMsg(errorSpan, '').removeClass('error');
    }
    
    var minChar = 2;
    var maxChar = 3;
    var defaultGenre = 13;
    
    $('input').focus( function(){ $(this).addClass('current_input'); });
    $('input').blur( function(){ $(this).removeClass('current_input'); });
    
    title.blur(function() {
        var that = $(this);
        var errorSpan = "#form-name";
        
        if( title.val() == '' || that.val().length < minChar ) {
            addErrorClass(that, errorSpan, 'Naslov mora sadržavati mininalno 2 znaka');
        } else if( that.val().length >= minChar ) {
            rmErrorClass(that, errorSpan);
        }
    });
    
    genre.blur(function() {
        if( $(this).val() == 0 ) {
            $(this).val(defaultGenre);
        }
    });
    
    year.blur(function() {
        var that = $(this);
        var errorSpan = "#form-year";
        
        if( that.val() == 0 ) {
            addErrorClass(that, errorSpan, 'Godina nije odabrana');
        } else {
            rmErrorClass(that, errorSpan);
        }
    });
    
    duration.blur(function() {
        var that = $(this);
        var errorSpan = "#form-duration";
        
        if( that.val() == '' ) {
            addErrorClass(that, errorSpan, 'Upišite trajanje filma<br />');
        }
        else if( isNaN(that.val()) || that.val().length > maxChar ) {
            addErrorClass(that, errorSpan, 'Trajanje mora biti broj ne veći od 3 znamenke');
        } else {
            rmErrorClass(that, errorSpan);
        }
    });
    
    $('#insert_movie_form').on('submit', function(e) {
        if( title.val() == '' || year.val() == 0 || duration.val() == '' ) {
            //alert('Error');
            e.preventDefault();
        }
    });

    
});
$(function() {

	$('.close').on('click', function() {
		$(this).parent().slideUp(200);
	});

});
    </section>
</main>

<footer id="footer" class="clear">
    <p>Stiiv &copy; <?php echo date('Y'); ?></p>
</footer>

</div><!--END WRAPPER -->

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"></script>
<script src="<?php echo BASE_URL.JS; ?>main.js"></script>
</body>
</html>
<!DOCTYPE html>
<html lang="hr">
<head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="<?php echo BASE_URL.CSS; ?>style.css" />
    <title><?php echo $this->title; ?></title>
</head>

<body>

<div id="wrapper">

<header id="header">
    <a href="<?php echo BASE_URL.DEFAULT_CONTROLLER; ?>" class="home">
    	<h1>Contacts</h1>
    </a>
</header>

<nav id="main-menu">
    <?php include "navigation.php"; ?>
</nav>

<main id="content">
    <section>
<?php if( isset($_SESSION['id_user']) ) : ?>
	<ul>
	    <li><a href="<?php echo BASE_URL.'contacts'; ?>">Contacts</a></li>
	    <li>
	    	<a href="<?php echo BASE_URL.'contacts'.DS.'insert'; ?>">
	    		Unesi novi kontakt
	    	</a>
	    </li>
	    <!--USERNAME-->
	    <li id="username-menu">
	    	<a href="<?php echo "#"; ?>">
	    		User: <?php echo $this->var_check($username); ?> &dtrif;
	    	</a>
	    	<ul>
	    		<li>
	    			<a href="<?php echo BASE_URL.'contacts'.DS."logout"; ?>">
	    				Log out
	    			</a>
	    		</li>
	    	</ul>
	    </li><!--END USERNAME-->
	</ul>
<!-- SEARCH FORM -->
	<aside>
		<form action="<?php echo BASE_URL; ?>contacts/search" method="post">
	        <input id="search" type="text" name="search" />
	        <input id="search-btn" type="submit" value="Traži" />
	    </form>
	</aside>
<?php else: ?>
	<form id="login-form" action="<?php echo BASE_URL; ?>main/login" method="POST">
		<label for="username">Username</label>
		<input id="username" type="text" name="username" autofocus="autofocus" />

		<label for="password">Password</label>
		<input id="password" type="password" name="password" />

		<input type="submit" value="Log in" />
	</form>
<?php endif; ?>
<!DOCTYPE html>
<html lang="hr">
<head>
	<meta charset="UTF-8" />
	<link rel="stylesheet" type="text/css" href="<?php echo CSS; ?>style.css" />
	<title>Default template</title>
</head>

<body>

	<header>
		<h1>Contacts</h1>
	</header>

	<nav>
		<ul>
			<li><a href="#">Enter new contacts</a></li>
		</ul>
	</nav>

	<main>
		<section>

		</section>
	</main>

	<footer>
		<p>Stiiv &copy; <?php echo date('Y'); ?></p>
	</footer>

	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/mustache.js/0.8.1/mustache.min.js"></script>
    <script src="<?php echo JS; ?>main.js"></script>
</body>
</html>
<div class="contacts">
<p><?php if(isset($results_num)) echo $results_num; ?>: <?php echo isset($contact_num) ? $contact_num : 0; ?></p>
<?php if( isset($no_contacts) ) echo "<h2>{$no_contacts}</h2>"; ?>

<?php //$action_ ?>
<?php if( isset($action_message) ) : ?>

    <div class="position-relative <?php echo $this->var_check($succ_or_err);?>" style="padding: 1%;">
        <?php echo "<p>{$action_message}</p>"; ?>
        <span class="close">Close</span>
    </div>

<?php endif; ?>

<?php if( isset($contacts) ): ?>
    <table class="main-table">
        <tr>
            <th>Ime</th>
            <th>Prezime</th>
            <th>Mobitel 1</th>
            <th>Mobitel 2</th>
            <th>Kućni</th>
            <th>Posao</th>
            <th>Action</th>
        </tr>
    <?php foreach($contacts as $contact): ?>

        <tr>
            <td>
                <a class="view-contact" href="<?php echo BASE_URL.'contacts'.DS.'view'.DS.$contact->ID; ?>">
                    <?php Session::set('page', $this->var_check($_GET['page'])); ?>
                    <?php echo $contact->ime; ?>
                </a>
            </td>
            <td><?php echo $contact->prezime; ?></td>
            <td><?php echo $contact->mob1; ?></td>
            <td><?php echo $contact->mob2; ?></td>
            <td><?php echo $contact->kucni; ?></td>
            <td><?php echo $contact->posao; ?></td>
            <td>
                <a class="view-contact" href="<?php echo BASE_URL.'contacts'.DS.'edit'.DS.$contact->ID; ?>">
                    Uredi
                </a>
                <a class="view-contact" href="<?php echo BASE_URL.'contacts'.DS.'delete'.DS.$contact->ID; ?>" 
                    onclick="return confirm('Izbrisati <?php echo $contact->ime; ?>.\nJeste li sigurni?')">
                    Briši
                </a>
            </td>
        </tr>

    <?php endforeach; ?>
    </table>
<?php endif; ?>
</div>

<?php if( isset($pagination) ): ?>
    <div class="pagination">
        <?php echo $pagination; ?>
    </div>
<?php endif; ?>
<?php if( isset($contact) ) : ?>

    <?php
        $back_page = (Session::get('page') != null) ? Session::get('page') : 1;
        $back_link = '<a class="back-link" href="'.BASE_URL.'contacts?page='.$back_page.'">';
            $back_link .= '&xlarr; Natrag';
        $back_link .= '</a>';

    ?>

    <div class="contacts">

        <!-- MESSAGE DIV -->
        <?php if(isset($errorMsg)):  ?>
            <div class="message edit-message <?php echo $this->var_check($succ_or_err); ?> position-relative">
                <?php echo "<p>".$errorMsg."</p>"; ?>
                <span class="close">Close</span>
            </div>
        <?php endif; ?>

        <?php echo $back_link; ?>

        <a class="back-link" href="<?php echo BASE_URL.'contacts'.DS.'delete'.DS.$contact->ID; ?>" 
            onclick="return confirm('Izbrisati <?php echo $contact->ime; ?>.\nJeste li sigurni?')">
            Briši
        </a>

        <form id="edit-contact" action="<?php echo BASE_URL.'contacts/edit/'.$contact->ID; ?>" method="post" enctype="multipart/form-data">

            <table class="main-table">
                <tr>
                    <td class="bold">Ime:</td>
                    <td><input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : $contact->ime; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Prezime:</td>
                    <td><input type="text" name="last_name" value="<?php echo isset($_POST['last_name']) ? $_POST['last_name'] : $contact->prezime; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Mobitel 1:</td>
                    <td><input type="text" name="mob1" value="<?php echo isset($_POST['mob1']) ? $_POST['mob1'] : $contact->mob1; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Mobitel 2:</td>
                    <td><input type="text" name="mob2" value="<?php echo isset($_POST['mob2']) ? $_POST['mob2'] : $contact->mob2; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Kućni:</td>
                    <td><input type="text" name="home_tel" value="<?php echo isset($_POST['home_tel']) ? $_POST['home_tel'] : $contact->kucni; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Posao:</td>
                    <td><input type="text" name="job_tel" value="<?php echo isset($_POST['job_tel']) ? $_POST['job_tel'] : $contact->posao; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Grad:</td>
                    <td>
                        <select name="city">
                            <option value="0">Odaberite:</option>
                    <?php

                        if(isset($cities)) {
                            foreach($cities as $city) {
                                if( isset($_POST['city']) && $_POST['city'] == $city->id ) {
                                    $selected = 'selected="selected"';

                                } elseif(!isset($_POST['city']) && $contact->id_grada == $city->id) {
                                    $selected = 'selected="selected"';

                                } else {
                                    $selected = '';
                                }
                                echo 
                                '<option '.$selected.' value="'.$city->id.'">'.$city->ime.'</option>';
                            }
                        }

                        ?>
                        </select>
                </td>
                </tr>

                <tr>
                    <td class="bold">Opis:</td>
                    <td>
                        <textarea name="desc_contact">
                            <?php echo isset($_POST['desc_contact']) ? $_POST['desc_contact'] : $contact->opis; ?>
                        </textarea>
                    </td>
                </tr>

                <tr>
                    <td>Slika:</td>
                    <td>
                        <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
                        <input type="file" name="contact_pic" />
                        <img id="view-contact-pic" alt="Contact picture" src="<?php echo BASE_URL.IMAGES.'contacts'.DS.$contact->slika; ?>" />
                    </td>
                </tr>

            </table>

            <?php echo $back_link; ?>
            <input class="back-link" type="submit" name="submit" value="Spremi promjene" />
            <input class="back-link" type="submit" name="cancel_edit" value="Poništi" />
        </form>

    </div><!--end Contacts-->
<?php endif; ?>
<div class="message">
	<h1><?php echo isset($this->title) ? $this->title : ''; ?></h1>
	<h2><?php echo isset($message) ? $message : ''; ?></h2>
	<p><?php echo isset($home_link) ? $home_link : ''; ?></p>
</div>
<?php if( isset($succ_or_err) ): ?>
    <div class="message <?php echo isset($succ_or_err) ? $succ_or_err: null; ?> position-relative">
        <?php echo isset($errorMsg) ? "<p>{$errorMsg}</p>" : null; ?>
        <span class="close">Close</span>
    </div>
<?php endif;?>
<form id="insert-new-contact" action="<?php echo BASE_URL.'contacts/save'?>" method="post" enctype="multipart/form-data">
    <fieldset>
    <legend><?php echo isset($form_title) ? $form_title : null; ?></legend>
    <table>
        <tr>
            <td>Ime:</td>
            <td><input type="text" name="name" value="<?php echo $this->var_check($_POST['name']); ?>" /></td>
        </tr>

        <tr>
            <td>Prezime:</td>
            <td><input type="text" name="last_name" value="<?php echo $this->var_check($_POST['last_name']); ?>" /></td>
        </tr>

        <tr>
            <td>Grad:</td>
            <td>
                <select name="city">
                    <option value="0">Odaberite:</option>
            <?php

            if(isset($cities)) {
                foreach($cities as $city) {
                    $selected = ( isset($_POST['city']) && $_POST['city'] == $city->id )
                        ? 'selected="selected"' : '';
                    echo
                    '<option '.$selected.' value="'.$city->id.'">'.$city->ime.'</option>';
                }
            }

            ?>
                </select>
            </td>
        </tr>

        <tr>
            <td>Mobitel 1:</td>
            <td><input type="text" name="mob1" value="<?php echo $this->var_check($_POST['mob1']); ?>" /></td>
        </tr>

        <tr>
            <td>Mobitel 2:</td>
            <td><input type="text" name="mob2" value="<?php echo $this->var_check($_POST['mob2']); ?>" /></td>
        </tr>

        <tr>
            <td>Kućni:</td>
            <td><input type="text" name="home_tel" value="<?php echo $this->var_check($_POST['home_tel']); ?>" /></td>
        </tr>

        <tr>
            <td>Posao:</td>
            <td><input type="text" name="job_tel" value="<?php echo $this->var_check($_POST['job_tel']); ?>" /></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="hidden" name="MAX_FILE_SIZE" value="1048576" /></td>
        </tr>

        <tr>
            <td>Slika:</td>
            <td><input type="file" name="contact_pic" /></td>
        </tr>

        <tr>
            <td>Opis:</td>
            <td><textarea name="desc_contact"><?php echo $this->var_check($_POST['desc_contact']); ?></textarea></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="Spremi" /></td>
        </tr>
    </table>
    </fieldset>
</form>
<?php if( isset($succ_or_err) ): ?>
    <div class="message <?php echo $this->var_check($succ_or_err); ?> position-relative">
        <?php echo isset($errorMsg) ? "<p>{$errorMsg}</p>" : null; ?>
        <span class="close">Close</span>
    </div>
<?php endif;?>
<form id="insert-new-contact" action="<?php echo BASE_URL; ?>main/register" method="post">
    <fieldset>
    <legend><?php echo $this->var_check($sign_up); ?></legend>
    <table>
        <tr>
            <td>Username:</td>
            <td><input type="text" name="username" value="<?php echo $this->var_check($_POST['username']) ?>" /></td>
        </tr>

        <tr>
            <td>Password:</td>
            <td><input type="password" name="password" value="<?php echo $this->var_check($_POST['password']) ?>" /></td>
        </tr>

        <tr>
            <td>Retype Password:</td>
            <td><input type="password" name="password_again" value="<?php echo $this->var_check($_POST['password_again']) ?>" /></td>
        </tr>

        <tr>
            <td>Ime:</td>
            <td><input type="text" name="first_name" value="<?php echo $this->var_check($_POST['first_name']) ?>" /></td>
        </tr>

        <tr>
            <td>Prezime:</td>
            <td><input type="text" name="last_name" value="<?php echo $this->var_check($_POST['last_name']) ?>" /></td>
        </tr>

        <tr>
            <td>E-mail:</td>
            <td><input type="email" name="email" value="<?php echo $this->var_check($_POST['email']) ?>" /></td>
        </tr>

        <tr>
            <td></td>
            <td><input type="submit" value="<?php echo $this->var_check($sign_up); ?>" /></td>
        </tr>
    </table>
    </fieldset>
</form>
<div class="message success">
    <h2><?php if( isset($success_message) ) echo $success_message; ?></h2>
</div>

<div style="width: 63.5%; margin-left: 5%; padding: 3%; text-align: center; margin-bottom: 10px;">
    <h3>Redirecting to the Main page....</h3>
    <img alt="loading..." src="<?php echo BASE_URL.IMAGES.'loading.gif'; ?>" />
</div>





<h2><?php echo isset($this->title) ? $this->title : ''; ?></h2>
<h3><?php echo $subtitle; ?></h3>
<p><?php echo $body; ?></p>
<?php if( isset($contact) ) : ?>

    <?php
        $back_page = (Session::get('page') != null) ? Session::get('page') : 1;
        $back_link = '<a class="back-link" href="'.BASE_URL.'contacts?page='.$back_page.'">';
            $back_link .= '&xlarr; Natrag';
        $back_link .= '</a>';

    ?>

    <div class="contacts">

        <?php echo $back_link; ?>

        <a class="back-link" href="<?php echo BASE_URL.'contacts'.DS.'delete'.DS.$contact->ID; ?>" 
            onclick="return confirm('Izbrisati <?php echo $contact->ime; ?>.\nJeste li sigurni?')">
            Briši
        </a>

        <?php if(Session::get('errorMsg') != null):  ?>
            <div class="message failure position-relative">
                <?php echo "<p>".Session::get('errorMsg')."</p>"; ?>
                <span class="close">Close</span>
                <!-- DELETE SESSION MESSAGE AFTER DISPLAYING IT -->
                <?php unset($_SESSION['errorMsg']); ?>
            </div>
        <?php endif; ?>

        <form id="edit-contact" action="<?php echo BASE_URL.'contacts/update/'.$contact->ID; ?>" method="post" enctype="multipart/form-data">

            <table class="main-table">
                <tr>
                    <td class="bold">Ime:</td>
                    <td><input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : $contact->ime; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Prezime:</td>
                    <td><input type="text" name="last_name" value="<?php echo isset($_POST['last_name']) ? $_POST['last_name'] : $contact->prezime; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Mobitel 1:</td>
                    <td><input type="text" name="mob1" value="<?php echo isset($_POST['mob1']) ? $_POST['mob1'] : $contact->mob1; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Mobitel 2:</td>
                    <td><input type="text" name="mob2" value="<?php echo isset($_POST['mob2']) ? $_POST['mob2'] : $contact->mob2; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Kućni:</td>
                    <td><input type="text" name="home_tel" value="<?php echo isset($_POST['home_tel']) ? $_POST['home_tel'] : $contact->kucni; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Posao:</td>
                    <td><input type="text" name="job_tel" value="<?php echo isset($_POST['job_tel']) ? $_POST['job_tel'] : $contact->posao; ?>" /></td>
                </tr>

                <tr>
                    <td class="bold">Grad:</td>
                    <td>
                        <select name="city">
                            <option value="0">Odaberite:</option>
                    <?php

                        if(isset($cities)) {
                            foreach($cities as $city) {
                                $selected = ( isset($_POST['city']) && $_POST['city'] == $city->id )
                                    ? 'selected="selected"' : '';
                                echo
                                '<option '.$selected.' value="'.$city->id.'">'.$city->ime.'</option>';
                            }
                        }

                        ?>
                        </select>
                </td>
                </tr>

                <tr>
                    <td class="bold">Opis:</td>
                    <td>
                        <textarea name="desc_contact">
                            <?php echo isset($_POST['desc_contact']) ? $_POST['desc_contact'] : $contact->opis; ?>
                        </textarea>
                    </td>
                </tr>

                <tr>
                    <td>Slika:</td>
                    <td>
                        <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
                        <input type="file" name="contact_pic" />
                        <img id="view-contact-pic" alt="Contact picture" src="<?php echo BASE_URL.IMAGES.'contacts'.DS.$contact->slika; ?>" />
                    </td>
                </tr>

            </table>

            <?php echo $back_link; ?>
            <input class="back-link" type="submit" name="submit" value="Spremi promjene" />
            <input class="back-link" type="submit" name="cancel_edit" value="Poništi" />
        </form>

    </div><!--end Contacts-->
<?php endif; ?>
<?php if( isset($contact) ) : ?>

    <?php
        $back_page = (Session::get('page') != null) ? Session::get('page') : 1;
        $back_link = '<a class="back-link" href="'.BASE_URL.'contacts?page='.$back_page.'">';
            $back_link .= '&xlarr; Natrag';
        $back_link .= '</a>';

    ?>

    <div class="contacts">
        <!-- MESSAGE DIV -->
        <?php if( Session::get("action_message") != null ):  ?>
        <div class="message edit-message <?php echo ( Session::get("succ_or_err") != null ) ? Session::get("succ_or_err") : "" ; ?> position-relative">
            <?php echo "<p>".Session::get("action_message")."</p>"; ?>
            <span class="close">Close</span>
        </div>
        <?php unset($_SESSION['action_message'], $_SESSION['succ_or_err']); ?>

        <?php endif; ?>
        <?php echo $back_link; ?>

        <a class="back-link" href="<?php echo BASE_URL.'contacts'.DS.'edit'.DS.$contact->ID; ?>">
            Uredi
        </a>

        <a class="back-link" href="<?php echo BASE_URL.'contacts'.DS.'delete'.DS.$contact->ID; ?>" 
            onclick="return confirm('Izbrisati <?php echo $contact->ime; ?>.\nJeste li sigurni?')">
            Briši
        </a>

        <table class="main-table">
            <tr>
                <td class="bold">Ime:</td>
                <td><?php echo $contact->ime; ?></td>
            </tr>

            <tr>
                <td class="bold">Prezime:</td>
                <td><?php echo $contact->prezime; ?></td>
            </tr>

            <tr>
                <td class="bold">Mobitel 1:</td>
                <td><?php echo $contact->mob1; ?></td>
            </tr>

            <tr>
                <td class="bold">Mobitel 2:</td>
                <td><?php echo $contact->mob2; ?></td>
            </tr>

            <tr>
                <td class="bold">Kućni:</td>
                <td><?php echo $contact->kucni; ?></td>
            </tr>

            <tr>
                <td class="bold">Posao:</td>
                <td><?php echo $contact->posao; ?></td>
            </tr>

            <tr>
                <td class="bold">Grad:</td>
                <td><?php echo $contact->ime_grada; ?></td>
            </tr>

            <tr>
                <td class="bold">Opis:</td>
                <td><?php echo $contact->opis; ?></td>
            </tr>

            <tr>
                <td>Slika:</td>
                <td>
                    <img id="view-contact-pic" alt="Contact picture" src="<?php echo BASE_URL.IMAGES.'contacts'.DS.$contact->slika; ?>" />
                </td>
            </tr>
        </table>

        <?php echo $back_link; ?>
    </div>
<?php endif; ?>