new permission manager
diff --git a/hr/doctype/leave_application/leave_application.txt b/hr/doctype/leave_application/leave_application.txt
index edebe4b..6af6529 100644
--- a/hr/doctype/leave_application/leave_application.txt
+++ b/hr/doctype/leave_application/leave_application.txt
@@ -2,9 +2,9 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-12-10 10:25:20", 
+  "creation": "2012-12-19 12:46:47", 
   "modified_by": "Administrator", 
-  "modified": "2012-12-18 11:06:54"
+  "modified": "2013-01-01 15:13:51"
  }, 
  {
   "is_submittable": 1, 
@@ -28,6 +28,7 @@
   "parent": "Leave Application", 
   "read": 1, 
   "doctype": "DocPerm", 
+  "write": 1, 
   "parenttype": "DocType", 
   "parentfield": "permissions"
  }, 
@@ -49,6 +50,7 @@
   "description": "Leave can be approved by users with Role, \"Leave Approver\"", 
   "doctype": "DocField", 
   "label": "Leave Approver", 
+  "options": "link:Profile", 
   "fieldname": "leave_approver", 
   "fieldtype": "Select", 
   "permlevel": 0
@@ -90,6 +92,7 @@
   "permlevel": 0
  }, 
  {
+  "print_width": "50%", 
   "doctype": "DocField", 
   "width": "50%", 
   "fieldname": "column_break1", 
@@ -115,29 +118,32 @@
   "in_filter": 1
  }, 
  {
+  "read_only": 1, 
   "search_index": 0, 
   "doctype": "DocField", 
   "label": "Employee Name", 
   "fieldname": "employee_name", 
   "fieldtype": "Data", 
-  "permlevel": 1, 
+  "permlevel": 0, 
   "in_filter": 1
  }, 
  {
+  "read_only": 1, 
   "no_copy": 1, 
   "doctype": "DocField", 
   "label": "Leave Balance Before Application", 
   "fieldname": "leave_balance", 
   "fieldtype": "Currency", 
-  "permlevel": 1
+  "permlevel": 0
  }, 
  {
+  "read_only": 1, 
   "no_copy": 1, 
   "doctype": "DocField", 
   "label": "Total Leave Days", 
   "fieldname": "total_leave_days", 
   "fieldtype": "Currency", 
-  "permlevel": 1
+  "permlevel": 0
  }, 
  {
   "doctype": "DocField", 
@@ -157,6 +163,7 @@
   "permlevel": 2
  }, 
  {
+  "read_only": 0, 
   "search_index": 0, 
   "doctype": "DocField", 
   "label": "Fiscal Year", 
@@ -168,6 +175,7 @@
   "in_filter": 1
  }, 
  {
+  "read_only": 0, 
   "print_hide": 1, 
   "doctype": "DocField", 
   "label": "Letter Head", 
@@ -177,38 +185,27 @@
   "permlevel": 2
  }, 
  {
+  "print_hide": 1, 
+  "no_copy": 1, 
   "doctype": "DocField", 
   "label": "Amended From", 
+  "options": "Sales Invoice", 
   "fieldname": "amended_from", 
-  "fieldtype": "Data", 
-  "permlevel": 2
- }, 
- {
-  "doctype": "DocField", 
-  "label": "Amendment Date", 
-  "fieldname": "amendment_date", 
-  "fieldtype": "Date", 
-  "permlevel": 2
+  "fieldtype": "Link", 
+  "permlevel": 1
  }, 
  {
   "create": 1, 
   "doctype": "DocPerm", 
-  "write": 1, 
   "role": "Employee", 
   "permlevel": 0, 
   "match": "employee"
  }, 
  {
-  "doctype": "DocPerm", 
-  "role": "All", 
-  "permlevel": 1
- }, 
- {
   "amend": 1, 
   "create": 1, 
   "doctype": "DocPerm", 
   "submit": 1, 
-  "write": 1, 
   "role": "HR User", 
   "cancel": 1, 
   "permlevel": 0
@@ -218,7 +215,6 @@
   "create": 1, 
   "doctype": "DocPerm", 
   "submit": 1, 
-  "write": 1, 
   "role": "Leave Approver", 
   "cancel": 1, 
   "permlevel": 0, 
@@ -226,7 +222,6 @@
  }, 
  {
   "doctype": "DocPerm", 
-  "write": 1, 
   "role": "HR User", 
   "permlevel": 2
  }, 
@@ -235,14 +230,8 @@
   "create": 0, 
   "doctype": "DocPerm", 
   "submit": 0, 
-  "write": 1, 
   "role": "Leave Approver", 
   "cancel": 0, 
   "permlevel": 2
- }, 
- {
-  "doctype": "DocPerm", 
-  "role": "All", 
-  "permlevel": 3
  }
 ]
\ No newline at end of file
diff --git a/patches/january_2013/__init__.py b/patches/january_2013/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/patches/january_2013/__init__.py
diff --git a/patches/january_2013/remove_bad_permissions.py b/patches/january_2013/remove_bad_permissions.py
new file mode 100644
index 0000000..58d5de2
--- /dev/null
+++ b/patches/january_2013/remove_bad_permissions.py
@@ -0,0 +1,7 @@
+import webnotes
+
+def execute():
+	webnotes.conn.sql("""update tabDocPerm set permlevel=0 where permlevel is null""")
+	webnotes.conn.sql("""update tabDocPerm set `create`=0, `submit`=0, `cancel`=0,
+		`amend`=0, `match`='' where permlevel>0""")
+	webnotes.delete_doc("Permission Control")
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index b1ebdef..318ce25 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -574,4 +574,8 @@
 		'patch_module': 'patches.december_2012',
 		'patch_file': 'update_print_width',
 	},
+	{
+		'patch_module': 'patches.january_2013',
+		'patch_file': 'remove_bad_permissions',
+	},	
 ]
\ No newline at end of file
diff --git a/setup/page/setup/setup.html b/setup/page/setup/setup.html
index 1e7607f..676dd17 100644
--- a/setup/page/setup/setup.html
+++ b/setup/page/setup/setup.html
@@ -23,10 +23,14 @@
 				<span class="help">Add/remove users, set roles, passwords etc</span>
 			</p>
 			<p>
-				<b><a href="#Permission Engine">Permission Manager</a></b><br>
+				<b><a href="#user-properties">Permission Manager</a></b><br>
 				<span class="help">Set permissions on transactions / masters</span>
 			</p>
 			<p>
+				<b><a href="#permission-manager">User Properties</a></b><br>
+				<span class="help">Set default values for users (also used for permissions).</span>
+			</p>
+			<p>
 				<b><a href="#List/Workflow">Workflow Manager</a></b><br>
 				<span class="help">Set workflow rules.</span>
 			</p>
@@ -118,12 +122,6 @@
 				<b><a href="#List/Print Heading">Print Headings</a></b><br>
 				<span class="help">Add headers for standard print formats</span>
 			</p>
-			<!--
-			<p>
-				<b><a href="#Form/Personalize/Personalize">Home Banner</a></b><br>
-				<span class="help">Add a home page banner</span>
-			</p>
-			-->
 			<p>
 				<b><a href="#Form/Style Settings/Style Settings">Style Settings</a></b><br>
 				<span class="help">Change background fonts etc</span>
diff --git a/utilities/doctype/question/question.txt b/utilities/doctype/question/question.txt
index b63df41..ef9d7d3 100644
--- a/utilities/doctype/question/question.txt
+++ b/utilities/doctype/question/question.txt
@@ -2,24 +2,18 @@
  {
   "owner": "Administrator", 
   "docstatus": 0, 
-  "creation": "2012-03-27 14:36:01", 
+  "creation": "2012-07-03 13:30:42", 
   "modified_by": "Administrator", 
-  "modified": "2012-03-27 14:36:01"
+  "modified": "2013-01-01 18:58:55"
  }, 
  {
-  "section_style": "Simple", 
-  "allow_attach": 0, 
-  "module": "Utilities", 
-  "allow_trash": 1, 
-  "server_code_error": " ", 
-  "in_create": 1, 
   "read_only": 1, 
   "autoname": "QUES.#######", 
+  "in_create": 1, 
   "name": "__common__", 
-  "colour": "White:FFF", 
   "doctype": "DocType", 
-  "show_in_menu": 0, 
-  "version": 7
+  "module": "Utilities", 
+  "allow_attach": 0
  }, 
  {
   "name": "__common__", 
@@ -32,10 +26,10 @@
  {
   "parent": "Question", 
   "read": 1, 
-  "doctype": "DocPerm", 
   "cancel": 1, 
   "name": "__common__", 
   "create": 1, 
+  "doctype": "DocPerm", 
   "write": 1, 
   "parenttype": "DocType", 
   "role": "All", 
@@ -47,9 +41,6 @@
   "doctype": "DocType"
  }, 
  {
-  "doctype": "DocPerm"
- }, 
- {
   "oldfieldtype": "Text", 
   "doctype": "DocField", 
   "label": "Question", 
@@ -80,40 +71,10 @@
   "hidden": 1
  }, 
  {
-  "search_index": 0, 
   "doctype": "DocField", 
-  "label": "Tag 1", 
-  "oldfieldname": "tag_1", 
-  "fieldname": "tag_1", 
-  "fieldtype": "Link", 
-  "oldfieldtype": "Link", 
-  "options": "Question Tag"
- }, 
- {
-  "doctype": "DocField", 
+  "label": "Users Voted", 
   "fieldname": "_users_voted", 
-  "fieldtype": "Text", 
-  "label": "Users Voted"
- }, 
- {
-  "search_index": 0, 
-  "doctype": "DocField", 
-  "label": "Tag 2", 
-  "oldfieldname": "tag_2", 
-  "fieldname": "tag_2", 
-  "fieldtype": "Link", 
-  "oldfieldtype": "Link", 
-  "options": "Question Tag"
- }, 
- {
-  "search_index": 0, 
-  "doctype": "DocField", 
-  "label": "Tag 3", 
-  "oldfieldname": "tag_3", 
-  "fieldname": "tag_3", 
-  "fieldtype": "Link", 
-  "oldfieldtype": "Link", 
-  "options": "Question Tag"
+  "fieldtype": "Text"
  }, 
  {
   "oldfieldtype": "Text", 
@@ -123,5 +84,8 @@
   "fieldname": "file_list", 
   "fieldtype": "Text", 
   "hidden": 1
+ }, 
+ {
+  "doctype": "DocPerm"
  }
 ]
\ No newline at end of file
diff --git a/website/utils.py b/website/utils.py
index b7fd88d..96fbdc8 100644
--- a/website/utils.py
+++ b/website/utils.py
@@ -145,7 +145,7 @@
 	
 	if page_name in get_template_pages():
 		args = webnotes._dict({
-			'template': 'pages/%s' % page_name,
+			'template': 'pages/%s.html' % page_name,
 			'name': page_name,
 		})
 		if page_name in page_settings_map: