{"repo": "schamane/node-syslog", "pr_number": 34, "title": "Build an empty addon on win32", "state": "closed", "merged_at": null, "additions": 29, "deletions": 5, "files_changed": ["node-syslog.js", "test.js"], "files_before": {"node-syslog.js": "var SyslogWrapper = require('./build/Release/syslog');\n\n/*\n * export Syslog as module\n */\nmodule.exports = {\n\ninit: SyslogWrapper.init,\nlog: SyslogWrapper.log,\nsetMask: SyslogWrapper.setMask,\nclose: SyslogWrapper.close,\nversion: '1.1.7',\n\n/*\n * facilities\n */\nLOG_KERN\t\t: (0<<3),\nLOG_USER\t\t: (1<<3),\nLOG_MAIL\t\t: (2<<3),\nLOG_DAEMON\t\t: (3<<3),\nLOG_AUTH\t\t: (4<<3),\nLOG_SYSLOG\t\t: (5<<3),\nLOG_LPR\t\t\t: (6<<3),\nLOG_NEWS\t\t: (7<<3),\nLOG_UUCP\t\t: (8<<3),\nLOG_LOCAL0\t\t: (16<<3),\nLOG_LOCAL1\t\t: (17<<3),\nLOG_LOCAL2\t\t: (18<<3),\nLOG_LOCAL3\t\t: (19<<3),\nLOG_LOCAL4\t\t: (20<<3),\nLOG_LOCAL5\t\t: (21<<3),\nLOG_LOCAL6\t\t: (22<<3),\nLOG_LOCAL7\t\t: (23<<3),\n\n/*\n * option flag for openlog\n */\nLOG_PID\t\t\t: 0x01,\nLOG_CONS\t\t: 0x02,\nLOG_ODELAY\t\t: 0x04,\nLOG_NDELAY\t\t: 0x08,\nLOG_NOWAIT\t\t: 0x10,\nLOG_PERROR\t\t: 0x20,\n/*\n * priorities\n */\nLOG_EMERG\t\t: 0,\nLOG_ALERT\t\t: 1,\nLOG_CRIT\t\t: 2,\nLOG_ERR\t\t\t: 3,\nLOG_WARNING\t\t: 4,\nLOG_NOTICE\t\t: 5,\nLOG_INFO\t\t: 6,\nLOG_DEBUG\t\t: 7\n};\n\n/*\n * Attach destroy handling\n *\n * XXX(sam) consider using AtExit: joyent/node#e4a8d261\n */\nprocess.on('exit', function() {\n\tSyslogWrapper.close();\n});\n", "test.js": "var assert = require('assert');\nvar Syslog = require('./node-syslog');\n\nassert.throws(function() {\n Syslog.init();\n}, Error);\n\nSyslog.init(\"node-syslog-test\", Syslog.LOG_PID | Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0);\nSyslog.log(Syslog.LOG_INFO, \"news info log test\");\nSyslog.log(Syslog.LOG_ERR, \"news log error test\");\nSyslog.log(Syslog.LOG_DEBUG, \"Last log message as debug: \" + new Date());\nSyslog.close();\n\nconsole.log('PASS');\n"}, "files_after": {"node-syslog.js": "var SyslogWrapper = require('./build/Release/syslog');\n\n/*\n * export Syslog as module\n */\nmodule.exports = {\n\ninit: SyslogWrapper.init,\nlog: SyslogWrapper.log,\nsetMask: SyslogWrapper.setMask,\nclose: SyslogWrapper.close,\nversion: '1.1.7',\n\n/*\n * facilities\n */\nLOG_KERN\t\t: (0<<3),\nLOG_USER\t\t: (1<<3),\nLOG_MAIL\t\t: (2<<3),\nLOG_DAEMON\t\t: (3<<3),\nLOG_AUTH\t\t: (4<<3),\nLOG_SYSLOG\t\t: (5<<3),\nLOG_LPR\t\t\t: (6<<3),\nLOG_NEWS\t\t: (7<<3),\nLOG_UUCP\t\t: (8<<3),\nLOG_LOCAL0\t\t: (16<<3),\nLOG_LOCAL1\t\t: (17<<3),\nLOG_LOCAL2\t\t: (18<<3),\nLOG_LOCAL3\t\t: (19<<3),\nLOG_LOCAL4\t\t: (20<<3),\nLOG_LOCAL5\t\t: (21<<3),\nLOG_LOCAL6\t\t: (22<<3),\nLOG_LOCAL7\t\t: (23<<3),\n\n/*\n * option flag for openlog\n */\nLOG_PID\t\t\t: 0x01,\nLOG_CONS\t\t: 0x02,\nLOG_ODELAY\t\t: 0x04,\nLOG_NDELAY\t\t: 0x08,\nLOG_NOWAIT\t\t: 0x10,\nLOG_PERROR\t\t: 0x20,\n/*\n * priorities\n */\nLOG_EMERG\t\t: 0,\nLOG_ALERT\t\t: 1,\nLOG_CRIT\t\t: 2,\nLOG_ERR\t\t\t: 3,\nLOG_WARNING\t\t: 4,\nLOG_NOTICE\t\t: 5,\nLOG_INFO\t\t: 6,\nLOG_DEBUG\t\t: 7\n};\n\n/*\n * Attach destroy handling\n *\n * XXX(sam) consider using AtExit: joyent/node#e4a8d261\n */\nif (SyslogWrapper.close) {\n\tprocess.on('exit', function() {\n\t\tSyslogWrapper.close();\n\t});\n}\n", "test.js": "var assert = require('assert');\nvar Syslog = require('./node-syslog');\n\nif (process.platform == \"win32\") {\n assert(Syslog.init === undefined);\n console.log('PASS');\n return;\n}\n\nassert.throws(function() {\n Syslog.init();\n}, Error);\n\nSyslog.init(\"node-syslog-test\", Syslog.LOG_PID | Syslog.LOG_ODELAY, Syslog.LOG_LOCAL0);\nSyslog.log(Syslog.LOG_INFO, \"news info log test\");\nSyslog.log(Syslog.LOG_ERR, \"news log error test\");\nSyslog.log(Syslog.LOG_DEBUG, \"Last log message as debug: \" + new Date());\nSyslog.close();\n\nconsole.log('PASS');\n"}} {"repo": "trel/MPACT", "pr_number": 1, "title": "Php7", "state": "closed", "merged_at": "2021-05-07T04:46:11Z", "additions": 483, "deletions": 431, "files_changed": ["mpact.php", "mpact_include.php"], "files_before": {"mpact.php": " \"N/A\",\n \"-1\" => \"N/A\",\n \"0\" => \"Incomplete - Not_Inspected\",\n \"1\" => \"Incomplete - Inspected\",\n \"2\" => \"Incomplete - Ambiguous\",\n \"3\" => \"Complete - Except Indecipherables\",\n \"4\" => \"Fully Complete\"\n);\n\n$inspectioncodes = array(\n NULL => \"N/A\",\n \"0\" => \"No\",\n \"1\" => \"Yes\"\n);\n\n$degree_types = array(\n \"Unknown\",\n \"Unknown - Investigated\",\n \"A.L.A.\",\n \"B.A.\",\n \"B.S.\",\n \"B.L.S.\",\n \"L.L.B.\",\n \"H.A.\",\n \"M.A.\",\n \"M.S.\",\n \"M.F.A.\",\n \"M.P.A.\",\n \"D.E.A.\",\n \"Ed.M.\",\n \"F.L.A. (by thesis)\",\n \"LL.M.\",\n \"LL.D.\",\n \"M.L.S.\",\n \"D.S.N.\",\n \"D.S.W.\",\n \"D.Engr.\",\n \"D.Lib.\",\n \"Ed.D.\",\n \"Th.D.\",\n \"Pharm.D.\",\n \"D.Sc.\",\n \"D.L.S.\",\n \"J.D.\",\n \"M.D.\",\n \"Ph.D.\"\n);\n\n// Begin Session\nsession_start();\n\n// Delete server session if client cookie doesn't exist\nif (!isset($_COOKIE['MPACT_userid'])){\n unset($_SESSION['MPACT']);\n}\n\n// Check for good cookie (and expired session) - (re)set session values accordingly\nif (isset($_COOKIE['MPACT_userid']) && !isset($_SESSION['MPACT'])){\n $query = \"SELECT id, username, fullname FROM users WHERE id='\".$_COOKIE['MPACT_userid'].\"'\";\n $result = mysql_query($query) or die(mysql_error());\n $line = mysql_fetch_array($result);\n $_SESSION['MPACT']['userid'] = $line['id'];\n $_SESSION['MPACT']['username'] = $line['username'];\n $_SESSION['MPACT']['fullname'] = $line['fullname'];\n}\n\n###############################################\n// DISPLAY SOMETHING - something from the URL\nif ($_SERVER['REQUEST_METHOD'] == 'GET')\n{\n // Display header\n xhtml_web_header();\n\n// echo \"-----\\n\";\n// print_r($_COOKIE);\n// echo \"-----\\n\";\n// print_r($_SESSION);\n// echo \"-----\\n\";\n if (isset($_GET['op']))\n {\n switch ($_GET['op'])\n {\n ###############################################\n case \"login\";\n\n $host_info = get_environment_info();\n if ($host_info['hostname'] == \"sils\"){\n # no logins here - go to dev server\n action_box(\"No Logins Here...\",2,$_SERVER['SCRIPT_NAME']);\n }\n else{\n if (!isset($_SESSION['MPACT']['userid'])){\n # login form\n echo \"

Welcome

\\n\";\n echo \"

Please login if you have an account.

\\n\";\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"

Username:

Password:

     
\\n\";\n echo \"
\";\n }\n else{\n # um, already logged in...\n action_box(\"Already Logged In...\",2,$_SERVER['SCRIPT_NAME']);\n }\n }\n\n break;\n ###############################################\n case \"logout\";\n\n setcookie('MPACT_userid',$_SESSION['MPACT']['userid'],time()-1000);\n unset($_SESSION['MPACT']);\n action_box(\"Logged Out\",2,$_SERVER['SCRIPT_NAME']);\n\n break;\n ###############################################\n case \"glossary\";\n\n if ( isset($_GET['id']) ){\n show_glossaryterm($_GET['id']);\n }\n else\n {\n show_glossary();\n }\n\n break;\n ###############################################\n case \"admin\";\n\n if (is_admin())\n {\n echo \"

Administrator Pages

\\n\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"Show Logs\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"Show Orphans\\n\";\n echo \"
\\n\";\n echo \"Citation Correlation\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"People with Multiple Dissertations (Errors in DB)\\n\";\n echo \"
\\n\";\n echo \"Year 0000\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"Add a New Person to the Database\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"No Title/Abstract\\n\";\n echo \"
\\n\";\n echo \"LIS, No Title/Abstract\\n\";\n echo \"
\\n\";\n echo \"LIS, No Title\\n\";\n echo \"
\\n\";\n echo \"LIS, No Abstract\\n\";\n echo \"
\\n\";\n echo \"
\\n\";\n echo \"LIS, No Committee\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"LIS, Graduates By Year\\n\";\n echo \"
\\n\";\n echo \"LIS History\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"LIS Professors Summary\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with MPACT\\n\";\n echo \"
\\n\";\n echo \"LIS Professors and their Degrees (large CSV)\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with Unknown Degree\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with Unknown-Investigated Degree\\n\";\n echo \"
\\n\";\n echo \"LIS Professors without Dissertations\\n\";\n echo \"
\\n\";\n echo \"LIS Professors without LIS Dissertations\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"
\";\n\n show_alphabet();\n\n }\n else\n {\n not_admin();\n }\n\n break;\n ###############################################\n case \"glossary_edit\";\n\n if ( isset($_GET['id']) && is_admin() ){\n\n echo \"

Edit a Glossary Definition

\\n\";\n\n $query = \"SELECT id, term, definition FROM glossary WHERE id='\".$_GET['id'].\"'\";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $results['term'] = $line['term'];\n $results['definition'] = $line['definition'];\n }\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\".$results['term'].\":
\\n\";\n echo \"\\n\";\n echo \"
\\n\";\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n\n\n }\n else\n {\n not_admin();\n }\n\n break;\n ###############################################\n case \"show_tree\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n draw_tree((int)$_GET['id']);\n }\n\n break;\n\n ###############################################\n case \"show_graph\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n echo \"

\\n\";\n echo \"Advisors and Advisees of \".get_person_link($_GET['id']);\n echo \"

\\n\";\n draw_graph((int)$_GET['id']);\n }\n\n break;\n\n ###############################################\n case \"statistics\":\n\n echo \"

\\n\";\n echo \"LIS Incomplete - \\n\";\n echo \"Top A -\\n\";\n echo \"Top C -\\n\";\n echo \"Top A+C -\\n\";\n echo \"Top T -\\n\";\n echo \"Top G -\\n\";\n echo \"Top W -\\n\";\n echo \"Top TD -\\n\";\n echo \"Top TA\\n\";\n echo \"

\\n\";\n\n echo \"

Overall MPACT Statistics

\\n\";\n\n echo \"\\n\";\n\n # disciplines\n $query = \"SELECT count(*) as disciplinecount FROM disciplines\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # schools\n $query = \"SELECT count(*) as schoolcount FROM schools\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # diss\n $query = \"SELECT count(*) as disscount FROM dissertations\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # a\n $query = \"SELECT count(*) as advisorcount FROM advisorships\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # c\n $query = \"SELECT count(*) as committeeshipscount FROM committeeships\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # full\n $query = \"SELECT count(*) as peoplecount FROM people\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n echo \"
Disciplines\".$disciplinecount.\"
Schools\".$schoolcount.\"
Dissertations\".$disscount.\"
Advisorships\".$advisorcount.\"
Committeeships\".$committeeshipscount.\"
People\".$peoplecount.\"
\\n\";\n\n\n # dissertations by country\n echo \"

\\n\";\n echo \"

Dissertations by Country:


\\n\";\n $query = \"SELECT count(*) as dissnone FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"\\\")\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as dissusa FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"USA\\\")\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as disscanada FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"Canada\\\")\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as dissother FROM dissertations WHERE school_id IN\n (SELECT id FROM schools WHERE (country != \\\"\\\" AND country != \\\"USA\\\" AND country != \\\"Canada\\\"))\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"
USA\".$dissusa.\"\".sprintf(\"%.2f\",100*$dissusa/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa)/$disscount).\"%
Canada\".$disscanada.\"\".sprintf(\"%.2f\",100*$disscanada/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada)/$disscount).\"%
Other\".$dissother.\"\".sprintf(\"%.2f\",100*$dissother/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada+$dissother)/$disscount).\"%
None Listed\".$dissnone.\"\".sprintf(\"%.2f\",100*$dissnone/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada+$dissother+$dissnone)/$disscount).\"%
Total\".$disscount.\"\".sprintf(\"%.2f\",100*$disscount/$disscount).\"%
\\n\";\n\n # dissertations by year\n echo \"

\\n\";\n echo \"

Dissertations by Year:


\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations GROUP BY completedyear\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n\n break;\n\n\n ###############################################\n case \"show_logs\":\n\n if (is_admin())\n {\n echo \"

Recent Activity

\\n\";\n\n if (isset($_GET['offset']))\n {\n $entries = get_logs($_GET['offset']);\n }\n else\n {\n $entries = get_logs();\n }\n echo \"\\n\";\n foreach ($entries as $entry)\n {\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
\".$entry['logged_at'].\"
\".$entry['ip'].\"
\".$entry['user'].\"\".$entry['message'].\"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_multi_dissertations\":\n\n if (is_admin())\n {\n echo \"

People With Multiple Dissertations (db needs to be edited by hand)

\\n\";\n \n $query = \"SELECT\n count(d.id) as howmany,\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n GROUP BY\n d.person_id\n ORDER BY\n howmany DESC\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $multicount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n if ($d['howmany'] > 1)\n {\n print \"person id = \".$d['person_id'];\n print \"
\";\n print \"
\";\n $multicount++;\n }\n }\n if ($multicount == 0)\n {\n print \" - None - database is clear.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_zero_year\":\n\n if (is_admin())\n {\n echo \"

Dissertations from the year 0000

\\n\";\n \n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.discipline_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.completedyear = '0000'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n # get school\n $query = \"SELECT fullname\n FROM\n schools\n WHERE id = '\".$d['school_id'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $schoolname = $line['fullname'];\n }\n # get degree\n $query = \"SELECT degree\n FROM\n people\n WHERE id = '\".$d['person_id'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $degree = $line['degree'];\n }\n $discipline = find_discipline($d['discipline_id']);\n echo \"\";\n echo \"\";\n echo \"\";\n print \"\";\n print \"\";\n print \"\";\n print \"\";\n }\n if ($zerocount == 0)\n {\n print \"\";\n }\n echo \"
$zerocount.\".get_person_link($d['person_id']).\"$degree\".$discipline['title'].\"$schoolname
None - database is clear.
\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Title

\\n\";\n \n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.title = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have titles.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_abstract_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Abstract

\\n\";\n \n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.abstract = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_abstract\":\n\n if (is_admin())\n {\n echo \"

Dissertations Without Title/Abstract

\\n\";\n \n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.title = '' OR d.abstract = ''\n ORDER BY\n d.school_id\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All dissertations have titles and abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_abstract_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Title/Abstract

\\n\";\n \n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.title = '' OR d.abstract = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertations = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have titles and abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_unknown_degree\":\n \n if (is_admin())\n {\n echo \"

LIS Professors with Unknown Degree

\\n\";\n \n # advisors or committee members with unknown degree,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n $lis_with_unknown = array();\n\n # get advisors for each diss, check for advisor's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $advisors = array();\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n foreach($advisors as $aid){\n $adv = find_person($aid);\n if ($adv['degree'] == \"Unknown\"){\n $lis_with_unknown[] = $aid;\n }\n }\n }\n\n # get committeeships for each diss, check for comm's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $committeemembers = array();\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n foreach($committeemembers as $cid){\n $com = find_person($cid);\n if ($com['degree'] == \"Unknown\"){\n $lis_with_unknown[] = $cid;\n }\n }\n }\n\n # uniquify\n $lis_with_unknown = array_unique($lis_with_unknown);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($lis_with_unknown as $pid){\n $count++;\n $person = find_person($pid);\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_unknowninvestigated\":\n case \"lis_profs_unknowninvestigated_degree\":\n \n# if (is_admin())\n# {\n echo \"

LIS Professors with Unknown-Investigated Degree

\\n\";\n \n # advisors or committee members with unknown-investigated degree,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n $lis_with_unknown = array();\n\n # get advisors for each diss, check for advisor's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $advisors = array();\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n foreach($advisors as $aid){\n $adv = find_person($aid);\n if ($adv['degree'] == \"Unknown - Investigated\"){\n $lis_with_unknown[] = $aid;\n }\n }\n }\n\n # get committeeships for each diss, check for comm's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $committeemembers = array();\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n foreach($committeemembers as $cid){\n $com = find_person($cid);\n if ($com['degree'] == \"Unknown - Investigated\"){\n $lis_with_unknown[] = $cid;\n }\n }\n }\n\n # uniquify\n $lis_with_unknown = array_unique($lis_with_unknown);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($lis_with_unknown as $pid){\n $count++;\n $person = find_person($pid);\n print \"$count. \";\n print get_person_link($pid);\n $advisorcount = count(find_advisorships_under_person($pid));\n $commcount = count(find_committeeships_under_person($pid));\n $totalcommitteeships = $advisorcount + $commcount;\n if ($totalcommitteeships > 1){print \"\";}\n print \" : $advisorcount + $commcount = $totalcommitteeships\";\n if ($totalcommitteeships > 1){print \"\";}\n print \"
\\n\";\n $allcommitteeships += $totalcommitteeships;\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n\n print \"
TOTAL COMMITTEESHIPS = $allcommitteeships
\";\n\n echo \"

\\n\";\n\n# }\n# else\n# {\n# not_admin();\n# }\n\n break;\n\n\n ###############################################\n case \"lis_profswithoutdiss\":\n\n if (is_admin())\n {\n echo \"

LIS Professors without Dissertations

\\n\";\n \n # advisors or committee members with no dissertation,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n $total = array_merge($advisors,$committeemembers);\n $unique = array_unique($total);\n\n $unique_list = implode(\",\",$unique);\n $listed = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $listed[] = $line['person_id'];\n }\n $notlisted = array_diff($unique,$listed);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($notlisted as $pid){\n $count++;\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_degrees\":\n\n if (is_admin())\n {\n echo \"

LIS Professors and their Degrees

\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n print \"

Copy and Paste the text below into a .csv file.

\";\n\n # big loop\n print \"
\\n\";\n          print \"
\";\n print \"Count,DissID,DissYear,DissLastName,DissFirstName,DissSchool,DissCountry,AdvisorID,AdvisorType,AdvisorLastName,AdvisorFirstName,\";\n print \"AdvisorDegree,AdvisorYear,AdvisorDiscipline,AdvisorSchool,AdvisorCountry\\n\";\n $count = 0;\n foreach($lis_dissertations as $did){\n # loop through advisors\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $did\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n\n # advisor line\n\n # Count\n $count++;\n print \"\\\"$count\\\",\";\n # DissID\n print \"\\\"$did\\\",\";\n # DissYear\n $diss = find_dissertation($did);\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # DissLastName\n $author = find_person($diss['person_id']);\n print \"\\\"\".$author['lastname'].\"\\\",\";\n # DissFirstName\n print \"\\\"\".$author['firstname'].\"\\\",\";\n # DissSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # DissCountry\n print \"\\\"\".$school['country'].\"\\\",\";\n # AdvisorID\n $pid = $line['person_id'];\n print \"\\\"$pid\\\",\";\n # AdvisorType\n print \"\\\"Advisor\\\",\";\n # AdvisorLastName\n $person = find_person($pid);\n print \"\\\"\".$person['lastname'].\"\\\",\";\n # AdvisorFirstName\n print \"\\\"\".$person['firstname'].\"\\\",\";\n # AdvisorDegree\n print \"\\\"\".$person['degree'].\"\\\",\";\n $diss = find_dissertation_by_person($pid);\n if ($diss){\n # AdvisorYear\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # AdvisorDiscipline\n $disc = find_discipline($diss['discipline_id']);\n print \"\\\"\".$disc['title'].\"\\\",\";\n # AdvisorSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # AdvisorCountry\n print \"\\\"\".$school['country'].\"\\\"\";\n }\n else{\n # no dissertation for this person\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\"\";\n }\n print \"\\n\";\n\n }\n # loop through committeeships\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $did\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n\n # committeeship line\n\n # Count\n $count++;\n print \"\\\"$count\\\",\";\n # DissID\n print \"\\\"$did\\\",\";\n # DissYear\n $diss = find_dissertation($did);\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # DissLastName\n $author = find_person($diss['person_id']);\n print \"\\\"\".$author['lastname'].\"\\\",\";\n # DissFirstName\n print \"\\\"\".$author['firstname'].\"\\\",\";\n # DissSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # DissCountry\n print \"\\\"\".$school['country'].\"\\\",\";\n # AdvisorID\n $pid = $line['person_id'];\n print \"\\\"$pid\\\",\";\n # AdvisorType\n print \"\\\"Committee\\\",\";\n # AdvisorLastName\n $person = find_person($pid);\n print \"\\\"\".$person['lastname'].\"\\\",\";\n # AdvisorFirstName\n print \"\\\"\".$person['firstname'].\"\\\",\";\n # AdvisorDegree\n print \"\\\"\".$person['degree'].\"\\\",\";\n $diss = find_dissertation_by_person($pid);\n if ($diss){\n # AdvisorYear\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # AdvisorDiscipline\n $disc = find_discipline($diss['discipline_id']);\n print \"\\\"\".$disc['title'].\"\\\",\";\n # AdvisorSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # AdvisorCountry\n print \"\\\"\".$school['country'].\"\\\"\";\n }\n else{\n # no dissertation for this person\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\"\";\n }\n print \"\\n\";\n\n }\n }\n echo \"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profsnotfromlis\":\n\n if (is_admin())\n {\n\n echo \"

LIS Professors without LIS Dissertations

\\n\";\n\n # and then once the data collection is done\n # cassidy wants a list of all the people who were advisors and committee\n # members for lis, but were not themselves lis\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n $total = array_merge($advisors,$committeemembers);\n $unique = array_unique($total);\n\n $unique_list = implode(\",\",$unique);\n $listed = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $listed[] = $line['person_id'];\n }\n $notlisted = array_diff($unique,$listed);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($notlisted as $pid){\n $count++;\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_nocommittee\":\n\n if (is_admin())\n {\n\n echo \"

LIS Dissertations with no committee

\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT count(*) as howmany\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n if ($line['howmany'] > 0){$hascomm[] = $id;};\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT count(*) as howmany\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n if ($line['howmany'] > 0){$hascomm[] = $id;};\n }\n }\n $unique = array_unique($hascomm);\n $nocomm = array_diff($lis_dissertations,$unique);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($nocomm as $did){\n $count++;\n print \"$count. \";\n $d = find_dissertation($did);\n print get_person_link($d['person_id']);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_with_mpact\":\n\n if (is_admin())\n {\n echo \"

LIS Professors With MPACT

\\n\";\n \n # advisors or committee members\n # that served on an lis dissertation\n\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n \n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n\n $total = array_merge($advisors,$committeemembers);\n\n $unique = array_unique($total);\n\n echo \"
\\n\";\n          echo \"Count|Name|Year|A|C|A+C|T\\n\";\n          foreach ($unique as $prof){\n            $mpact = mpact_scores($prof);\n            $person = find_person($prof);\n            $dissertation = find_dissertation_by_person($prof);\n            # count\n            $count += 1;\n            echo \"$count\";\n            echo \"|\";\n            # name\n            echo $person['fullname'];\n            echo \"|\";\n            # year\n            echo $dissertation['completedyear'];\n            echo \"|\";\n            # a\n            echo $mpact['A'];\n            echo \"|\";\n            # c\n            echo $mpact['C'];\n            echo \"|\";\n            # a+c\n            echo $mpact['AC'];\n            echo \"|\";\n            # t\n            echo $mpact['T'];\n            echo \"\\n\";\n          }\n          echo \"
\\n\";\n }\n\n break;\n\n ###############################################\n case \"lis_profs_summary\":\n \n if (is_admin())\n {\n echo \"

LIS Professors Summary

\\n\";\n \n # advisors or committee members\n # that served on an lis dissertation\n\n echo \"\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n echo \"\\n\";\n \n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n echo \"\\n\";\n\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n echo \"\\n\";\n\n $total = array_merge($advisors,$committeemembers);\n echo \"\\n\";\n\n $unique = array_unique($total);\n echo \"\\n\";\n\n $unique_list = implode(\",\",$unique);\n $known = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $known[] = $line['person_id'];\n }\n echo \"\\n\";\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n discipline_id != 16\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n completedyear != 0000\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n completedyear != 107\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n echo \"
Total LIS Dissertations\".count($lis_dissertations).\"
Total LIS Dissertation Advisorships\";\n echo count($advisors);\n echo \"
Total LIS Dissertation Committeeships\";\n echo count($committeemembers);\n echo \"
Total LIS Dissertation Advisorships and Committeeships:\";\n echo count($total);\n echo \"
Total number of unique advisor/committee members on LIS dissertations:\";\n\n echo count($unique);\n echo \"
\";\n echo \"Subset of \".count($unique).\" without a listed dissertation:\";\n echo count(array_diff($unique,$known));\n echo \"
Subset of \".count($unique).\" with a listed dissertation:\";\n echo count($known);\n echo \"
- Subset of \".count($known).\" with known discipline:\";\n echo $howmany;\n echo \"
- Subset of \".count($known).\" with known year:\";\n echo $howmany;\n echo \"
- Subset of \".count($known).\" with known school:\";\n echo $howmany;\n echo \"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_allyears\":\n\n if (is_admin())\n {\n echo \"

LIS, Graduates By Year

\\n\";\n print \"
\\n\";\n\n            # get list of dissertations\n            $query = \"SELECT\n                      d.id, d.person_id, d.completedyear\n                    FROM\n                      dissertations d\n                    WHERE\n                      d.discipline_id = '1'\n                    ORDER BY\n                      d.completedyear ASC,\n                      d.school_id ASC\n                    \";\n            $result = mysql_query($query) or die(mysql_error());\n            $schools = array();\n            $count = 0;\n            while ( $line = mysql_fetch_array($result)) {\n              $dissertation = find_dissertation($line['id']);\n              $person = find_person($line['person_id']);\n              $schoolinfo = find_persons_school($line['person_id']);\n              $count++;\n              print $count;\n              print \"|\";\n              print $line['completedyear'];\n              print \"|\";\n              print $schoolinfo['school'];\n              print \"|\";\n              print $person['fullname'];\n#              print \"|\";\n#              print $dissertation['title'];\n#              print \"|\";\n#              print $dissertation['abstract'];\n              print \"\\n\";\n            }\n\n            print \"
\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_history\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations by School by Year

\\n\";\n\n $firstyear = 1920;\n $lastyear = 2008;\n\n print \"
\\n\";\n            print \"school|\";\n            for ($i = $firstyear; $i <= $lastyear; $i++)\n            {\n                print \"$i|\";\n            }\n            print \"\\n\";\n\n            # get list of schools (all of them)\n            $query = \"SELECT\n                    s.id, s.fullname\n                    FROM\n                      schools s\n                    ORDER BY\n                      s.fullname\n                    \";\n            $result = mysql_query($query) or die(mysql_error());\n            $schools = array();\n            while ( $line = mysql_fetch_array($result)) {\n              $schools[] = $line;\n            }\n            foreach ($schools as $s)\n            {\n              # loop through each school and find count by year\n              $query = \"SELECT\n                    d.id, d.person_id, d.completedyear, COUNT(d.completedyear) AS yeartotal\n                    FROM\n                      dissertations d\n                    WHERE\n                      d.discipline_id = '1' AND\n                      d.school_id = '\".$s['id'].\"'\n                    GROUP BY\n                      d.completedyear\n                  \";\n              $result = mysql_query($query) or die(mysql_error());\n\n              print $s['fullname'].\"|\";\n              $d = array();\n              while ( $line = mysql_fetch_array($result)) {\n                $d[$s['id']][$line['completedyear']] = $line['yeartotal'];\n              }\n\n              # walk through all years, and print out counts for this school\n              for ($i = $firstyear; $i <= $lastyear; $i++)\n              {\n                if ($d[$s['id']][$i] > 0)\n                  print $d[$s['id']][$i].\"|\";\n                else\n                  print \"0|\";\n              }\n              print \"\\n\";\n            }\n\n            print \"
\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_incomplete\":\n\n echo \"

Incomplete LIS Dissertation Listings

\\n\";\n\n $discipline_id = 1; # hard coded for LIS\n $schools = find_schools($discipline_id);\n\n foreach ($schools as $one => $two)\n {\n\n $year_conferred = array();\n $degree_status = array();\n\n $query = \"SELECT d.person_id, d.completedyear, d.status\n FROM\n dissertations d,\n schools s,\n people p,\n names n\n WHERE\n s.id = '$one' AND\n d.discipline_id = '$discipline_id' AND\n d.school_id = s.id AND\n d.person_id = p.id AND\n p.preferred_name_id = n.id AND\n d.status < 4\n ORDER BY\n s.id ASC, d.completedyear ASC, n.lastname ASC, n.firstname ASC\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n $resultcount = 0;\n\n while ( $line = mysql_fetch_array($result)) {\n $resultcount++;\n extract($line);\n $year_conferred[$person_id] = $completedyear;\n $degree_status[$person_id] = $status;\n }\n\n if ($resultcount > 0)\n {\n echo \"

$two

\\n\";\n }\n\n $incompletecount = 0;\n echo \"\";\n foreach ($year_conferred as $person => $year)\n {\n $incompletecount++;\n $printme = \"\\n\";\n $printme .= \"\\n\";\n\n $printme .= \"\\n\";\n $printme .= \"\\n\";\n\n echo $printme;\n }\n echo \"
$incompletecount. \";\n $printme .= \"\".get_person_link($person).\" ($year)\".$statuscodes[$degree_status[$person]].\"
\";\n\n }\n echo \"

\";\n\n break;\n\n ###############################################\n case \"all_edges\":\n\n if (is_admin())\n {\n echo \"

All Dissertations and Mentor Relationships

\\n\";\n\n print \"
\\n\";\n            print \"mentor|role|protege|year|school\\n\";\n\n            # each dissertation\n            $query = \"SELECT id, person_id, completedyear, school_id FROM dissertations\";\n            $result = mysql_query($query) or die(mysql_error());\n            while ( $line = mysql_fetch_array($result)) {\n              extract($line);\n              $student = find_person($person_id);\n              $query2 = \"SELECT fullname as schoolname FROM schools WHERE id = '$school_id'\";\n              $result2 = mysql_query($query2) or die(mysql_error());\n              $line2 = mysql_fetch_array($result2);\n              extract($line2);\n              print $student['fullname'].\"|dissertation|null|$completedyear|$schoolname\\n\";\n              # get advisorships\n              $advisors = find_advisors_for_person($person_id);\n              foreach ($advisors as $mentor_id){\n                $mentor = find_person($mentor_id);\n                print $mentor['fullname'].\"|advisorship|\".$student['fullname'].\"|$completedyear|$schoolname\\n\";\n              }\n              # get committeeships\n              $committee = find_committee_for_person($person_id);\n              foreach ($committee as $mentor_id){\n                $mentor = find_person($mentor_id);\n                print $mentor['fullname'].\"|committeeship|\".$student['fullname'].\"|$completedyear|$schoolname\\n\";\n              }\n            }\n            print \"
\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"citation_correlation\":\n\n if (is_admin())\n {\n echo \"

Citation Correlation Data

\\n\";\n\n $correlated_ids = array(\n 953,\n 2098,\n# 5086, bc\n 3659,\n# 1329, dalhousie\n 5087,\n 478,\n 3094,\n 3497,\n 4784,\n 1250,\n 5088,\n 5089,\n 5090,\n 4657,\n# 5091, mcdowell, not phd yet\n 5092,\n 5093,\n 5094,\n 2668,\n 4076,\n 2683,\n 3978,\n 2425,\n 3645,\n 2660,\n 2233,\n 2665,\n 1310,\n 2548,\n 2708,\n 2592,\n 4648,\n 5095,\n 5096,\n 4654,\n 5097,\n 5098,\n 1234,\n 1299,\n 1294,\n 3062,\n 3110,\n 1283,\n 1220,\n 874,\n 584,\n 3127,\n 1142,\n 3116,\n 5099,\n 5100,\n 1025,\n 486,\n 3130,\n 1321,\n 5101,\n 4502,\n 5102,\n 535,\n 5160, # koohang\n 2673,\n 5103,\n 5104,\n 1950,\n 3972,\n 3278,\n 5105,\n 3571,\n 5106,\n 3994,\n 1504,\n 4181,\n 3140,\n 2323, # benoit added\n 5107,\n 800,\n 4438,\n 5108,\n 5109,\n 4760,\n 2570,\n 1866,\n 3238,\n 1846,\n 1806,\n 2527,\n 3703,\n 4758,\n 3683,\n 3846,\n 2603,\n 4011,\n 2343,\n 2329,\n 5110,\n 5111,\n 4706,\n 2761,\n 1413,\n 3028,\n 3590,\n 3668,\n 2883,\n 3063,\n 3091,\n 1705,\n 3031,\n# gary again 486,\n 3979,\n 3018,\n 1855,\n 3409,\n 2747,\n 3093,\n 3065,\n 3060,\n 1685,\n 2114,\n 5112,\n# moore rm 5113,\n 2309,\n# liu rm 2215,\n 4086,\n 4013,\n 1573\n );\n\n echo \"\\n\";\n echo \"\n \n \n \n \n \n \n \n \n \n \\n\";\n $counter = 0;\n foreach ($correlated_ids as $one)\n {\n $counter++;\n echo \"\";\n echo \"\";\n echo \"\";\n $scores = mpact_scores($one);\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
-NameACA+CFMIFMEFMI/(A+C)FME/(A+C)
$counter.\";\n echo get_person_link($one);\n echo \"\".$scores['A'].\"\".$scores['C'].\"\".$scores['AC'].\"\".$scores['FMI'].\"\".$scores['FME'].\"\".$scores['FMIdivFULL'].\"\".$scores['FMEdivFULL'].\"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"top_a\":\n case \"top_c\":\n case \"top_ac\":\n case \"top_g\":\n case \"top_td\":\n case \"top_w\":\n case \"top_t\":\n case \"top_ta\":\n\n $list_type = strtoupper(substr($_GET['op'],4));\n echo \"

Top \";\n if ($list_type == \"TD\"){echo \"TD\";}\n else if ($list_type == \"TA\"){echo \"TA\";}\n else if ($list_type == \"AC\"){echo \"A+C\";}\n else {echo $list_type;}\n echo \" List

\\n\";\n $score_type = strtolower($list_type).\"_score\";\n $people = find_all_people();\n foreach ($people as $p)\n {\n $scores[$p] = find_mpact_score($p,$score_type);\n }\n # zero out indecipherables\n $scores[28] = 0;\n $scores[391] = 0;\n asort($scores);\n $scores = array_reverse($scores, true);\n $top = narray_slice($scores, 0, 100); #calls custom function, end of mpact_include (passes true)\n $count = 0;\n $lasttotal = 0;\n echo \"\\n\";\n foreach ($top as $one => $two)\n {\n $count++;\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n $lasttotal = $two;\n }\n echo \"
\";\n if ($two != $lasttotal){echo $count.\".\";}\n echo \"\";\n echo get_person_link($one);\n echo \"\";\n echo $two;\n echo \"
\\n\";\n break;\n\n ###############################################\n case \"create_discipline\":\n\n if (is_admin())\n {\n echo \"

Creating a New Discipline

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
Title
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_discipline\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n elseif (!is_empty_discipline($_GET['id']))\n {\n action_box(\"Discipline must be empty to edit...\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else{\n \n $query = \"SELECT title FROM disciplines WHERE id=\".$_GET['id'];\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

Editing a Discipline

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
Title
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_school\":\n\n if (is_admin())\n {\n echo \"

Creating a New School

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FullnameCountry
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n elseif (!is_empty_school($_GET['id']))\n {\n action_box(\"School must be empty to edit...\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else{\n \n $query = \"SELECT fullname, country FROM schools WHERE id=\".$_GET['id'];\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

Editing a School

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FullnameCountry
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_person\":\n\n if (is_admin())\n {\n echo \"

Creating a New Person

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffixDegree
\";\n echo \"\\n\";\n echo \"
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_mentor\":\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n\n echo \"

Adding a Mentor

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Mentor Type:
\\n\";\n echo \" Advisor
\\n\";\n echo \" Committee Member\\n\";\n echo \"

\\n\";\n\n echo \"Mentor:
\\n\";\n echo \"\\n\";\n\n echo \"

\\n\";\n\n echo \"Student:
\\n\". get_person_link($_GET['id']);\n echo \"

\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_student\":\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n\n echo \"

Adding a Student

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Mentor Type:
\\n\";\n echo \" Advisor
\\n\";\n echo \" Committee Member\\n\";\n echo \"

\\n\";\n \n echo \"Mentor:
\\n\". get_person_link($_GET['id']);\n echo \"

\\n\";\n \n\n echo \"Student:
\\n\";\n echo \"\\n\";\n\n echo \"

\\n\";\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n\n ###############################################\n case \"remove_mentor\":\n\n if (is_admin())\n {\n echo \"

Removing a Mentor

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Are you sure you want to remove this mentor relationship?

\\n\";\n if ($_GET['type'] == \"A\"){echo \"Advisor: \";}\n if ($_GET['type'] == \"C\"){echo \"Commitee Member: \";}\n echo get_person_link(intval($_GET['mentor_id'])).\"
\\n\";\n echo \"Student: \".get_person_link(intval($_GET['student_id'])).\"
\\n\";\n echo \"
\\n\";\n\n echo \"\";\n echo \" If NOT, please go BACK\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree(intval($_GET['student_id']));\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_url\";\n\n if (is_admin())\n {\n echo \"

Adding a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:
Description:
\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree(intval($_GET['id']));\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_url\";\n\n if (is_admin())\n {\n $url = find_url(intval($_GET['id']));\n echo \"

Editing a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:
Description:
Last Updated:\".$url['updated_at'].\"
\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($url['person_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_url\";\n\n if (is_admin())\n {\n $url = find_url(intval($_GET['id']));\n echo \"

Deleting a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Are you sure you want to delete this Reference URL?

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:\".$url['url'].\"
Description:\".$url['description'].\"
Last Updated:\".$url['updated_at'].\"
\\n\";\n echo \"
\\n\";\n\n echo \"\";\n echo \" If NOT, please go BACK\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($url['person_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_degree\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Editing a Degree

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
NameDegree
\".$person['fullname'].\"\";\n echo \"\\n\";\n echo \"
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Adding an Alias

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n \n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffix
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n \n break;\n \n ###############################################\n case \"edit_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Editing a Name

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffix
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_dissertation\":\n\n if (is_admin())\n {\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n\n if (!$_GET['person_id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['person_id']);\n if (!$person)\n {\n action_box(\"Person not found.\");\n }\n else{\n\n echo \"

CREATE DISSERTATION

\\n\";\n\n echo \"
\";\n echo \"\";\n echo \"\";\n\n echo \"

\";\n echo get_person_link($person['id']);\n echo \"
\";\n\n echo \"Degree: \\n\";\n echo \"
\";\n\n echo \"Status: \\n\";\n echo \"
\";\n\n echo \"Discipline: \\n\";\n echo \"
\";\n\n\n echo \"School: \";\n echo \"\\n\";\n echo \"
Year:\\n\";\n echo \"
\";\n echo \"Title:

\";\n echo \"Abstract:

\";\n echo \"\";\n echo \"

\";\n\n echo \"
\";\n\n echo \"

\";\n echo \"Currently:\";\n echo \"

\";\n echo \"
\";\n draw_tree($person['id']);\n echo \"
\";\n }\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"edit_dissertation\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n $dissertation = find_dissertation(intval($_GET['id']));\n if (!$dissertation)\n {\n action_box(\"Dissertation not found.\");\n }\n else{\n \n $person = find_person($dissertation['person_id']);\n\n echo \"

EDIT DISSERTATION DETAILS

\\n\";\n\n echo \"
\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"

\";\n echo get_person_link($person['id']);\n echo \"
\";\n \n echo \"Degree: \\n\";\n echo \"
\";\n\n echo \"Status: \\n\";\n echo \"
\";\n\n echo \"Discipline: \\n\";\n echo \"
\";\n\n echo \"School: \\n\";\n\n echo \"
Year:\\n\";\n echo \"
\";\n echo \"Title:

\";\n echo \"Abstract:

\";\n echo \"Admin Notes:

\";\n echo \"\";\n echo \"

\";\n\n echo \"
\";\n\n echo \"

\";\n echo \"Currently:\";\n echo \"

\";\n echo \"
\";\n draw_tree($person['id']);\n echo \"
\";\n }\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_name($_GET['name']);\n\n echo \"

\";\n\n echo \"Are you sure you want to delete this name?\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\";\n \n echo \"

\";\n echo \"[ \".$person['firstname'].\" \".$person['middlename'].\" \".$person['lastname'].\" \".$person['suffix'].\" ]
\"; \n echo \"

\";\n\n\n echo \"

\";\n echo \"\";\n echo \"   Cancel

\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n \n ###############################################\n case \"set_preferred_name\":\n\n if (is_admin())\n {\n\n set_preferred_name($_GET['id'],$_GET['name']);\n\n action_box(\"Preferred Name Selected\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"recalculate_mpact\":\n\n if (is_admin()){\n\n # recalculate MPACT scores for passed person id\n calculate_scores($_GET['id']);\n\n action_box(\"MPACT Scores Recalculated\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_GET['id']);\n\n }\n else\n {\n not_admin();\n } \n\n break;\n\n ###############################################\n case \"show_orphans\":\n\n if (is_admin())\n {\n\n $orphans = find_orphans();\n\n echo \"

Orphans

\\n\";\n\n echo \"

\\n\";\n $counter = 0;\n foreach ($orphans as $orphan)\n {\n $counter++;\n echo $counter.\" \";\n echo get_person_link($orphan['person_id']);\n echo \" (Delete from Database)\";\n echo \"
\\n\";\n }\n if ($counter < 1){echo \" - No orphans at this time.\";}\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_person\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n if (is_orphan($_GET['id']))\n {\n echo \"

\";\n\n echo \"Are you sure you want to delete this person?\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n echo get_person_link($_GET['id']);\n echo \"

\";\n\n\n echo \"

\";\n echo \"

\\n\";\n echo \"\";\n echo \"   Cancel

\";\n\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n action_box(\"This person cannot be deleted.\");\n }\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"show_disciplines\":\n\n $statustotals = array(0,0,0,0,0);\n $disciplines = find_disciplines();\n $disciplinecounts = find_discipline_counts();\n\n if (is_admin()){\n echo \"

Add a New Discipline to the Database

\\n\";\n }\n\n echo \"

Disciplines Represented Across All Schools

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($disciplines as $one => $two)\n {\n echo \"\";\n echo \"\";\n $statuscounts = find_discipline_statuses($one);\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n if (!isset($disciplinecounts[$one]) || $disciplinecounts[$one]==0)\n {\n $fraction = 0;\n }\n else\n {\n $fraction = 100*$statuscounts[$three]/intval($disciplinecounts[$one]);\n }\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($disciplinecounts);\n echo \"\";\n }\n echo \"\";\n echo \"
Discipline$statuscodes[$one]
$two (\".intval($disciplinecounts[$one]).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($disciplines).\" Disciplines (\".array_sum($disciplinecounts).\" dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"show_discipline\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $discipline_id = intval($_GET['id']);\n\n # Show Discipline Name\n $query = \"SELECT d.title as disciplinename\n FROM disciplines d\n WHERE\n d.id = '$discipline_id'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

$disciplinename

\";\n\n # Show Histograph\n $counts = array();\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations WHERE discipline_id='$discipline_id' GROUP BY completedyear\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n if (count($counts)>0)\n {\n $bigyear = max($counts);\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*intval(200/$bigyear);\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n }\n echo \"

\\n\";\n }\n\n $schools = find_schools($discipline_id);\n $dissertation_count = 0;\n $statustotals = array(0,0,0,0,0);\n echo \"

Schools Represented

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($schools as $one => $two)\n {\n $statuscounts = find_dept_statuses($one,$discipline_id);\n $dissertation_count += array_sum($statuscounts);\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n $fraction = 100*$statuscounts[$three]/array_sum($statuscounts);\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n\n if (array_sum($statustotals)==0)\n {\n $fraction = 0;\n }\n else\n {\n $fraction = 100*$statustotals[$three]/array_sum($statustotals);\n }\n echo \"\";\n }\n echo \"\";\n echo \"
School$statuscodes[$one]
$two (\".array_sum($statuscounts).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($schools).\" Schools ($dissertation_count dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n # link to edit the discipline name\n if (is_empty_discipline($_GET['id']))\n {\n echo \"

\";\n echo \"

Edit Discipline Name

\\n\";\n }\n\n break;\n\n ###############################################\n case \"show_school\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $school_id = intval($_GET['id']);\n\n # Show School Name\n $query = \"SELECT s.fullname as schoolname, s.country\n FROM schools s\n WHERE\n s.id = '$school_id'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

$schoolname ($country)

\";\n\n # Show Histograph\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations WHERE school_id='$school_id' GROUP BY completedyear\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n $bigyear = max($counts);\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*intval(200/$bigyear);\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n\n $disciplines = find_disciplines($school_id);\n $dissertation_count = 0;\n $statustotals = array(0,0,0,0,0);\n echo \"

Disciplines Represented

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($disciplines as $one => $two)\n {\n $statuscounts = find_dept_statuses($school_id,$one);\n $dissertation_count += array_sum($statuscounts);\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n $fraction = 100*$statuscounts[$three]/array_sum($statuscounts);\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($statustotals);\n echo \"\";\n }\n echo \"\";\n echo \"
Discipline$statuscodes[$one]
$two (\".array_sum($statuscounts).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($disciplines).\" Disciplines ($dissertation_count dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n }\n\n # link to edit the school info\n if (is_empty_school($_GET['id']))\n {\n echo \"

\";\n echo \"

Edit School Information

\\n\";\n }\n\n break;\n\n ###############################################\n case \"show_schools\":\n\n $statustotals = array(0,0,0,0,0);\n $schools = find_schools();\n $schoolcounts = find_school_counts();\n\n if (is_admin()){\n echo \"

Add a New School to the Database

\\n\";\n }\n echo \"

Schools Represented Across All Disciplines

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($schools as $one => $two)\n {\n echo \"\";\n echo \"\";\n $statuscounts = find_school_statuses($one);\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n if (intval($schoolcounts[$one]) == 0){\n $fraction = 0;\n }\n else{\n $fraction = 100*$statuscounts[$three]/intval($schoolcounts[$one]);\n }\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($schoolcounts);\n echo \"\";\n }\n echo \"\";\n echo \"
School$statuscodes[$one]
$two (\".intval($schoolcounts[$one]).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($schools).\" Schools (\".array_sum($schoolcounts).\" dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"show_department\":\n\n if (!$_GET['d'] || !$_GET['s']){action_box(\"No ID given.\");}\n else\n {\n\n $school_id = $_GET['s'];\n $discipline_id = $_GET['d'];\n \n\n # Show Discipline Name\n $query = \"SELECT d.title as disciplinename\n FROM disciplines d\n WHERE\n d.id = '$discipline_id'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n # Show School Name\n $query = \"SELECT s.fullname as schoolname, s.country\n FROM schools s\n WHERE\n s.id = '$school_id'\n \";\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n echo \"\n

\n $disciplinename\n @\n $schoolname ($country)\n

\n \";\n\n # Advisor and Committee Activity\n echo \"

Dissertation Activity and MPACT Scores (click table headings to sort)

\";\n \n echo \"

\";\n $theprofs = find_profs_at_dept($school_id,$discipline_id);\n if (count($theprofs)>0)\n {\n $sortedprofs = array();\n $proflist = \"\";\n $query = \"SELECT id FROM people WHERE id IN (\";\n foreach ($theprofs as $prof){$proflist .= \"$prof,\";}\n $proflist = rtrim($proflist, \",\");\n $query .= \"$proflist) ORDER BY ac_score DESC\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $sortedprofs[] = $line['id'];\n }\n $profcount = 0;\n echo \"\\n\";\n echo \"\n \n \n \n \n \n \n \n \n \n \n \\n\";\n foreach ($sortedprofs as $one)\n {\n echo \"\";\n $profcount++;\n echo \"\";\n echo \"\";\n $scores = mpact_scores($one);\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
-NameACA+CGTTATDW
$profcount.\";\n echo get_person_link($one);\n echo \"\".$scores['A'].\"\".$scores['C'].\"\".$scores['AC'].\"\".$scores['G'].\"\".$scores['T'].\"\".$scores['TA'].\"\".$scores['TD'].\"\".$scores['W'].\"
\\n\";\n echo \"

\";\n }\n else\n {\n echo \"

- None Listed

\\n\";\n }\n echo \"
\";\n\n\n\n\n # Dissertations Conferred\n echo \"

Dissertations Conferred

\";\n\n\n\n\n # Show Histograph\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount\n FROM dissertations\n WHERE\n school_id='$school_id' AND\n discipline_id=$discipline_id\n GROUP BY\n completedyear\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*10;\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n\n\n\n\n $query = \"SELECT d.person_id, d.completedyear, d.status\n FROM\n dissertations d,\n schools s,\n people p,\n names n\n WHERE\n s.id = '$school_id' AND\n d.discipline_id = '$discipline_id' AND\n d.school_id = s.id AND\n d.person_id = p.id AND\n p.preferred_name_id = n.id\n ORDER BY\n d.completedyear ASC, n.lastname ASC, n.firstname ASC \n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n $year_conferred[$person_id] = $completedyear;\n $degree_status[$person_id] = $status;\n }\n\n $schoolcount = 0;\n echo \"

\";\n foreach ($year_conferred as $person => $year)\n {\n $schoolcount++;\n echo \"
$schoolcount. \";\n echo get_person_link($person);\n echo \" ($year)\";\n if ($degree_status[$person] < 4)\n {\n echo \" ---------------------------------- \".$statuscodes[$degree_status[$person]];\n }\n }\n echo \"

\";\n\n }\n\n break;\n \n ###############################################\n default:\n // oops - not supposed to be here\n action_box(\"invalid action\",1);\n }\n }\n else\n {\n\n if (isset($_GET['show']))\n {\n if ($_GET['show'] == \"all\")\n {\n $alphabet_limiter = \"\"; // set it to show everything\n }\n else\n {\n $alphabet_limiter = $_GET['show'];\n }\n\n show_alphabet();\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n }\n\n if (is_admin()){\n echo \"
\";\n echo \"\";\n echo \"\";\n echo \"\";\n }\n\n // GET ALL DISSERTATIONS IN A HASH\n $disciplines = find_disciplines();\n $query = \"SELECT id, person_id, discipline_id FROM dissertations\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $graduates[$line['person_id']] = $line['discipline_id'];\n }\n\n // LOOP THROUGH ALL PEOPLE FOR THIS LETTER\n echo \"\\n\";\n echo \"\\n\";\n if (is_admin()){echo \"\\n\";}\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n $query = \"SELECT n.id, n.firstname,\n n.middlename, n.lastname, n.suffix,\n p.id as person_id\n FROM names n, people p\n WHERE\n n.id = p.preferred_name_id AND\n n.lastname LIKE '\".$alphabet_limiter.\"%'\n ORDER BY n.lastname ASC, n.firstname ASC\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n $rowcount = 0;\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n\n $rowcount++;\n\n echo \"\";\n if (is_admin()){\n echo \"\";\n }\n echo \"\";\n echo \"\";\n $discipline = isset($graduates[$person_id]) ? $disciplines[$graduates[$person_id]] : \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n if (is_admin()){\n if ($rowcount % 25 == 0){\n echo \"\";\n }\n }\n\n }\n\n echo \"
MergeCountLast NameFull NameDissertation Discipline
$rowcount.$lastname$firstname $middlename $lastname $suffix$discipline
\\n\";\n\n if (is_admin()){\n echo \"\";\n echo \"
\";\n }\n\n echo \"

\\n\";\n\n show_alphabet();\n\n }\n else\n {\n // DISPLAY THE FRONT PAGE\n\n action_box(\"Front Page...\",0.1,\"./\");\n\n }\n\n }\n\n}\n\n\n\n\n\n\n\n\n\n###############################################\n// SOMETHING WAS SUBMITTED - through a form\nelse\n{\n\n if ($_POST['op'] != \"login\"){\n // Display header\n xhtml_web_header();\n }\n\n switch ($_POST['op'])\n {\n ###############################################\n case \"login\";\n\n $host_info = get_environment_info();\n if ($host_info['hostname'] == \"sils\"){\n # no logins here - go to dev server\n action_box(\"No Logins Here...\",2,$_SERVER['SCRIPT_NAME']);\n }\n else{\n # check credentials / start session\n $query = \"SELECT id, username, fullname FROM users\n WHERE username = '\".addslashes($_POST['username']).\"'\n AND password = '\".addslashes($_POST['password']).\"'\";\n $result = mysql_query($query) or die(mysql_error());\n $line = mysql_fetch_array($result);\n if (isset($line['id'])){\n # save cookie info for one week\n setcookie('MPACT_userid',$line['id'],time()+60*60*24*7);\n # redirect\n header(\"Location: \".$_SERVER['SCRIPT_NAME']);\n }\n else{\n // Display header\n xhtml_web_header();\n # incorrect credentials\n action_box(\"Please try again...\",2,$_SERVER['SCRIPT_NAME'].\"?op=login\");\n }\n }\n\n break;\n\n ###############################################\n case \"glossary_edit\";\n if (is_admin())\n {\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $query = \"UPDATE glossary\n SET\n definition = '\".$_POST['definition'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # log it\n mpact_logger(\"updated glossary [\".$_POST['term'].\" (\".$_POST['id'].\")] to (\".$_POST['definition'].\")\");\n\n action_box(\"Definition Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=glossary\");\n }\n else\n {\n not_admin();\n }\n break;\n\n ###############################################\n case \"merge_confirm\":\n \n if (is_admin()){\n\n echo \"
\";\n echo \"\";\n echo \"\";\n \n foreach ($_POST['mergers'] as $one)\n {\n echo \"
\";\n echo \"

[$one]

\";\n echo draw_tree( $one );\n echo \"\";\n echo \"
\";\n } \n\n echo \"\";\n echo \"
\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"search\":\n\n $results = people_search($_POST['q']);\n\n if (count($results) > 0)\n {\n echo \"

People Search Results for [\".$_POST['q'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['q'].\"].\";\n if (strlen($_POST['q']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n echo \"

Add a New Person to the Database

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"search_title_abstract\":\n\n $results = title_abstract_search($_POST['qta']);\n\n if (count($results) > 0)\n {\n echo \"

Title/Abstract Search Results for [\".$_POST['qta'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['qta'].\"].\";\n if (strlen($_POST['qta']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"search_notes\":\n\n if (is_admin()){\n\n $results = notes_search($_POST['qn']);\n\n if (count($results) > 0)\n {\n echo \"

Admin Notes Search Results for [\".$_POST['qn'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['qm'].\"].\";\n if (strlen($_POST['qn']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n } \n\n break;\n\n ###############################################\n case \"merge_doit\":\n \n if (is_admin()){\n\n # delete the family tree's dotgraphs of each person\n foreach ($_POST['mergers'] as $one)\n {\n delete_associated_dotgraphs($one);\n }\n\n # pop off one of the people_ids\n $into = array_pop($_POST['mergers']);\n\n # merge each remaining person into the one above\n foreach ($_POST['mergers'] as $one)\n {\n merge_two_people($one,$into);\n }\n\n # recalculate MPACT scores for merged person id\n calculate_scores($into);\n\n action_box(\"Merge was Successful\",2,$_SERVER['SCRIPT_NAME'].\"?show=\".$_POST['show']);\n\n }\n else\n {\n not_admin();\n } \n\n break;\n\n \n ###############################################\n case \"create_discipline\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['title'] == \"\")\n {\n action_box(\"Need to have at least a Discipline Title.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_discipline\");\n }\n elseif (is_duplicate_discipline($_POST['title']))\n {\n action_box(\"Discipline (\".$_POST['title'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else\n {\n \n # Create Discipline\n $query = \"INSERT disciplines\n SET\n title = '\".$_POST['title'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # Get the just created discipline_id\n $query = \"SELECT id as new_discipline_id, title FROM disciplines\n WHERE\n title = '\".$_POST['title'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n # log it\n mpact_logger(\"created discipline[\".$new_discipline_id.\"] (\".$title.\")\");\n\n action_box(\"Discipline Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_discipline\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['title'] == \"\")\n {\n action_box(\"Need to have at least a Discipline Title.\",3,$_SERVER['SCRIPT_NAME'].\"?op=edit_discipline&id=\".$_POST['discipline_id'].\"\");\n }\n elseif (is_duplicate_discipline($_POST['title']))\n {\n action_box(\"Discipline (\".$_POST['title'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else\n {\n\n # Edit Discipline\n $query = \"UPDATE disciplines\n SET\n title = '\".$_POST['title'].\"'\n WHERE\n id = '\".$_POST['discipline_id'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # log it\n mpact_logger(\"edited discipline[\".$_POST['discipline_id'].\"] (\".$_POST['title'].\")\");\n\n action_box(\"Discipline Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_school\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $_POST = array_map('trim',$_POST);\n\n if ($_POST['fullname'] == \"\" || $_POST['country'] == \"\")\n {\n action_box(\"Need to have at least a School name and Country.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_school\");\n }\n elseif (is_duplicate_school($_POST['fullname']))\n {\n action_box(\"School (\".$_POST['fullname'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else\n {\n\n # Create School\n $query = \"INSERT schools\n SET\n fullname = '\".$_POST['fullname'].\"',\n country = '\".$_POST['country'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # Get the just created school_id\n $query = \"SELECT id as new_school_id, fullname FROM schools\n WHERE\n fullname = '\".$_POST['fullname'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n # log it\n mpact_logger(\"created school[\".$new_school_id.\"] (\".$fullname.\")\");\n\n action_box(\"School Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['fullname'] == \"\" || $_POST['country'] == \"\")\n {\n action_box(\"Need to have at least a School name and Country.\",3,$_SERVER['SCRIPT_NAME'].\"?op=edit_school&id=\".$_POST['school_id'].\"\");\n }\n elseif (is_duplicate_school($_POST['fullname']))\n {\n action_box(\"School (\".$_POST['fullname'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else\n {\n\n # Edit School\n $query = \"UPDATE schools\n SET\n fullname = '\".$_POST['fullname'].\"',\n country = '\".$_POST['country'].\"'\n WHERE\n id = '\".$_POST['school_id'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # log it\n mpact_logger(\"edited school[\".$_POST['school_id'].\"] (\".$_POST['fullname'].\")\");\n\n action_box(\"School Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_person\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['lastname'] == \"\")\n {\n action_box(\"Need to have at least a Last Name.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_person\");\n }\n else\n {\n # Create Name\n $query = \"INSERT names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # Get the just created name_id\n $query = \"SELECT id as new_name_id FROM names\n WHERE\n firstname = '\".$_POST['firstname'].\"' AND\n middlename = '\".$_POST['middlename'].\"' AND\n lastname = '\".$_POST['lastname'].\"' AND\n suffix = '\".$_POST['suffix'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n # Create Person with new_name_id\n $query = \"INSERT people\n SET\n preferred_name_id = '\".$new_name_id.\"',\n degree = '\".$_POST['degree'].\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n # Get the just created person_id\n $query = \"SELECT id as new_person_id FROM people\n WHERE\n preferred_name_id = '\".$new_name_id.\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n # Sync them together with new_person_id\n $query = \"UPDATE names\n SET\n person_id = '\".$new_person_id.\"'\n WHERE\n id = '\".$new_name_id.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $after = find_person($new_person_id);\n\n action_box(\"Person Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$new_person_id);\n\n # log it\n mpact_logger(\"created person[\".$new_person_id.\"] (\".$after['fullname'].\")\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"remove_mentor\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if (remove_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']))\n {\n action_box(\"Mentor Removed\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['student_id']);\n }\n else\n {\n action_box(\"Nope.\");\n }\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_mentor\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n add_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']);\n\n action_box(\"Mentor Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['student_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_student\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n add_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']);\n\n action_box(\"Student Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['mentor_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_name\":\n \n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person($_POST['id']);\n\n $query = \"INSERT names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"',\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n # get the just created name_id\n $query = \"SELECT id as new_name_id FROM names\n WHERE\n firstname = '\".$_POST['firstname'].\"' AND\n middlename = '\".$_POST['middlename'].\"' AND\n lastname = '\".$_POST['lastname'].\"' AND\n suffix = '\".$_POST['suffix'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n \n # find that full name from the DB\n $added = find_name($new_name_id);\n\n action_box(\"Name Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n # log it\n mpact_logger(\"added name (\".$added['fullname'].\") for person[\".$_POST['id'].\"] (\".$person['fullname'].\")\");\n }\n else\n {\n not_admin();\n }\n \n break;\n\n ###############################################\n case \"edit_name\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $before = find_name($_POST['name_id']);\n \n $query = \"UPDATE names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"'\n WHERE\n id = '\".$_POST['name_id'].\"' AND\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n $after = find_name($_POST['name_id']);\n\n # delete dotgraph for this person\n delete_associated_dotgraphs($_POST['id']);\n\n action_box(\"Name Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n # log it\n mpact_logger(\"edited name[\".$_POST['name_id'].\"] for person[\".$_POST['id'].\"] from (\".$before['fullname'].\") to (\".$after['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person(intval($_POST['person_id']));\n\n $query = \"INSERT urls\n SET\n url = '\".$_POST['url'].\"',\n description = '\".$_POST['description'].\"',\n updated_at = now(),\n person_id = '\".$_POST['person_id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Reference URL Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id'].\"#urls\");\n # log it\n mpact_logger(\"added URL[\".substr($_POST['url'], 0, 30).\"] for person[\".$_POST['person_id'].\"] (\".$person['fullname'].\")\");\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $url = find_url(intval($_POST['id']));\n $person = find_person($url['person_id']);\n\n $query = \"UPDATE urls\n SET\n url = '\".$_POST['url'].\"',\n description = '\".$_POST['description'].\"',\n updated_at = now()\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Reference URL Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$url['person_id'].\"#urls\");\n # log it\n mpact_logger(\"edited URL[\".substr($_POST['url'], 0, 30).\"] for person[\".$url['person_id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $url = find_url(intval($_POST['id']));\n $person = find_person($url['person_id']);\n\n $query = \"DELETE FROM urls\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Reference URL Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$url['person_id'].\"#urls\");\n # log it\n mpact_logger(\"deleted URL[\".substr($url['url'], 0, 30).\"] for person[\".$url['person_id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_degree\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person(intval($_POST['id']));\n\n $query = \"UPDATE people\n SET\n degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Degree Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$person['id']);\n # log it\n mpact_logger(\"edited degree[\".$_POST['degree'].\"] for person[\".$person['id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_dissertation\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $schools = find_schools();\n\n $person = find_person($_POST['person_id']);\n\n $query = \"INSERT INTO dissertations\n SET\n person_id = '\".$_POST['person_id'].\"',\n discipline_id = '\".$_POST['discipline_id'].\"',\n school_id = '\".$_POST['school_id'].\"',\n completedyear = '\".$_POST['completedyear'].\"',\n status = '\".$_POST['status'].\"',\n title = '\".$_POST['title'].\"',\n abstract = '\".$_POST['abstract'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n $query = \"UPDATE people\n SET degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['person_id'].\"'\";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Dissertation Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id']);\n # log it\n $dissertation = find_dissertation_by_person($_POST['person_id']);\n mpact_logger(\"create dissertation[\".$dissertation['id'].\"] (\".$person['fullname'].\") with school[\".$dissertation['school_id'].\"] (\".$schools[$dissertation['school_id']].\") in year(\".$dissertation['completedyear'].\") with status (\".$statuscodes[$_POST['status']].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"edit_dissertation\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n\n $dissertation = find_dissertation($_POST['id']);\n $person = find_person($dissertation['person_id']);\n\n $query = \"UPDATE dissertations\n SET\n school_id = '\".$_POST['school_id'].\"',\n discipline_id = '\".$_POST['discipline_id'].\"',\n completedyear = '\".$_POST['completedyear'].\"',\n status = '\".$_POST['status'].\"',\n notes = '\".$_POST['notes'].\"',\n title = '\".$_POST['title'].\"',\n abstract = '\".$_POST['abstract'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n $query = \"UPDATE people\n SET degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['person_id'].\"'\";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Dissertation Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id']);\n # log it\n mpact_logger(\"edit dissertation[\".$_POST['id'].\"] (\".$person['fullname'].\") from school[\".$dissertation['school_id'].\"] (\".$schools[$dissertation['school_id']].\") in year(\".$dissertation['completedyear'].\") to school[\".$_POST['school_id'].\"] (\".$schools[$_POST['school_id']].\") in year(\".$_POST['completedyear'].\")\");\n # look for changes\n # degree\n if ($person['degree'] != $_POST['degree'])\n {\n mpact_logger($dissertation['id'].\" updated degree [\".$_POST['degree'].\"]\",\"dissertation\");\n }\n # discipline\n if ($dissertation['discipline_id'] != $_POST['discipline_id'])\n {\n mpact_logger($dissertation['id'].\" updated discipline [\".$_POST['discipline_id'].\" (\".$disciplines[$_POST['discipline_id']].\")]\",\"dissertation\");\n }\n # school\n if ($dissertation['school_id'] != $_POST['school_id'])\n {\n mpact_logger($dissertation['id'].\" updated school [\".$_POST['school_id'].\" (\".$schools[$_POST['school_id']].\")]\",\"dissertation\");\n }\n # year\n if ($dissertation['completedyear'] != $_POST['completedyear'])\n {\n mpact_logger($dissertation['id'].\" updated completedyear [\".$_POST['completedyear'].\"]\",\"dissertation\");\n }\n # title\n if ($dissertation['title'] != $_POST['title'])\n {\n mpact_logger($dissertation['id'].\" updated title [\".$_POST['title'].\"]\",\"dissertation\");\n }\n # abstract\n if ($dissertation['abstract'] != $_POST['abstract'])\n {\n mpact_logger($dissertation['id'].\" updated abstract [\".$_POST['abstract'].\"]\",\"dissertation\");\n }\n # status\n if ($dissertation['status'] != $_POST['status'])\n {\n mpact_logger($dissertation['id'].\" updated status [\".$statuscodes[$_POST['status']].\"]\",\"dissertation\");\n }\n # status\n if ($dissertation['notes'] != $_POST['notes'])\n {\n mpact_logger($dissertation['id'].\" updated notes [\".$_POST['notes'].\"]\",\"dissertation\");\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_person\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if (delete_person($_POST['id']))\n {\n action_box(\"Person Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']); \n }\n \n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"delete_name\":\n \n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $name = find_name($_POST['name_id']);\n $person = find_person($_POST['id']);\n\n $query = \"DELETE FROM names\n WHERE\n id = '\".$_POST['name_id'].\"' AND\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n action_box(\"Name Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n\n # log it\n mpact_logger(\"deleted name[\".$_POST['name_id'].\"] (\".$name['fullname'].\") from person[\".$person['id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n \n break;\n\n ###############################################\n default:\n // oops - not supposed to be here\n action_box(\"oops, back to the front page...\",2);\n\n\n }\n\n\n}\n\nxhtml_web_footer();\n\n?>\n", "mpact_include.php": " $val)\n foreach ($aSubtrahends as $aSubtrahend)\n if (array_key_exists($key, $aSubtrahend))\n unset ($ar1[$key]);\n return $ar1;\n}\n\n# -------------------------------------------------------------------------------\nfunction action_box($message,$bounce = \"0\",$location = \"index.php\"){\n\n echo \"\n

\n $message\n

\n

\n \";\n\n if ($bounce != \"0\"){\n echo \"\n \n

\n Forwarding in $bounce seconds (or click here to do the same)\n

\n \";\n }\n\n} \n\n# -------------------------------------------------------------------------------\nfunction xhtml_orig_web_header(){\n \n # make search box happy\n if (!isset($_POST['q'])){$_POST['q'] = \"\";}\n if (!isset($_POST['qta'])){$_POST['qta'] = \"\";}\n if (!isset($_POST['qn'])){$_POST['qn'] = \"\";}\n\n # print out header info\n echo \"\n \n \n \n \n MPACT\n \n \n \n \n\n \n \n \n \n \n \n \n \n \n
\n \n \n \n \n \n
\n
\n MPACT -\n Database -\n \n People Search: \n
-\n
\n \n Title/Abstract Search: \n
\n\";\n if (is_admin()){\n echo \" -
\n \n Admin Notes Search: \n
\";\n }\n echo \"
\n\";\n if (is_admin()){\n echo $_SESSION['MPACT']['fullname'].\" (\".$_SESSION['MPACT']['username'].\") - Logout\";\n }\n else{\n $host_info = get_environment_info();\n if ($host_info['hostname'] != \"sils\"){\n echo \"Login\";\n }\n }\necho \"\n
\n

\n\n \";\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction xhtml_web_header(){\n \n # make search box happy\n if (!isset($_POST['q'])){$_POST['q'] = \"\";}\n if (!isset($_POST['qta'])){$_POST['qta'] = \"\";}\n if (!isset($_POST['qn'])){$_POST['qn'] = \"\";}\n\n # print out header info\n echo \"\n \n \n \n \n MPACT\n \n \n \n \n \n \n\";\n\necho \"

\";\nif (is_admin()){\n echo $_SESSION['MPACT']['fullname'].\" (\".$_SESSION['MPACT']['username'].\") - Logout\";\n}\nelse{\n echo \"Login\";\n}\necho \"

\";\necho \"
\";\n\necho \"\n
\n \n \n \n \n \n \n\n \n \n \n
\n \n \n \n \n Publications  • \n Project Statistics\n
\n
\n Glossary  • \n Schools  • \n Disciplines\n
\n
\n \n People Search: \n
\n    \n
\n \n Title/Abstract Search: \n
\";\nif (is_admin()){\n echo \"

Administrator Pages\";\n echo \"
\n \n Admin Notes Search: \n
\";\n}\necho \"
\n \n
\n
\n\n
\n
\n\n
\n\n \";\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction xhtml_web_footer(){\n echo \"\n\n
\n\n \n \n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction is_email_valid ($address)\n{\n\n\t# http://www.zend.com/codex.php?id=285&single=1\n\n return (preg_match(\n '/^[-!#$%&\\'*+\\\\.\\/0-9=?A-Z^_`{|}~]+'. // the user name\n '@'. // the ubiquitous at-sign\n '([-0-9A-Z]+\\.)+' . // host, sub-, and domain names\n '([0-9A-Z]){2,4}$/i', // top-level domain (TLD)\n trim($address)));\n}\n\n# -------------------------------------------------------------------------------\nfunction find_glossaryterms()\n{\n $query = \"SELECT id, term, definition FROM glossary\";\n $result = mysql_query($query) or die(mysql_error());\n $glossaryterms = array();\n while ( $line = mysql_fetch_array($result)) {\n $glossaryterms['ids'][$line['term']] = $line['id'];\n $glossaryterms['defs'][$line['id']] = $line['definition'];\n }\n return $glossaryterms;\n}\n\n# -------------------------------------------------------------------------------\nfunction show_glossary()\n{\n $query = \"SELECT id, term, definition FROM glossary ORDER BY term ASC\";\n $result = mysql_query($query) or die(mysql_error());\n\n $results = array();\n while ( $line = mysql_fetch_array($result)) {\n array_push($results,$line);\n }\n\n echo \"

Glossary

\\n\";\n\n echo \"

\\n\";\n\n foreach ($results as $one)\n {\n echo \"\".$one['term'].\": \";\n echo $one['definition'];\n if (is_admin())\n {\n echo \" EDIT \";\n }\n echo \"

\";\n }\n\n echo \"

\\n\";\n\n}\n\n# -------------------------------------------------------------------------------\nfunction show_glossaryterm($id)\n{\n $query = \"SELECT id, term, definition FROM glossary WHERE id = $id\";\n $result = mysql_query($query) or die(mysql_error());\n\n $results = array();\n while ( $line = mysql_fetch_array($result)) {\n $glossaryterm = $line;\n }\n\n echo \"

Full Glossary Listing

\";\n\n echo \"

Glossary

\\n\";\n\n echo \"

\\n\";\n\n echo \"\".$glossaryterm['term'].\": \";\n echo $glossaryterm['definition'];\n if (is_admin())\n {\n echo \" EDIT \";\n }\n echo \"

\";\n\n echo \"

\\n\";\n\n}\n\n# -------------------------------------------------------------------------------\nfunction show_alphabet()\n{\n\n $alphabet_letters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n $alphabet = preg_split('//', $alphabet_letters, -1, PREG_SPLIT_NO_EMPTY);\n\n echo \"
\\n\";\n echo \"

Dissertation Authors and Mentors by Last Name

\";\n echo \"

\";\n foreach ($alphabet as $letter)\n {\n if ($letter != \"A\"){echo \" - \";}\n echo \"$letter\";\n }\n echo \"

\";\n echo \"
\\n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction search_box($q=\"\")\n{\n echo \"
\\n\";\n echo \"\\n\";\n echo \"

People Search: \";\n if ($q)\n {\n echo \"\\n\"; \n }\n else\n {\n echo \"\\n\"; \n }\n echo \"

\\n\";\n echo \"
\\n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction people_search($q)\n{\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = split(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$pieces[0].\"%' OR\n n.middlename LIKE '%\".$pieces[0].\"%' OR\n n.lastname LIKE '%\".$pieces[0].\"%' OR\n n.suffix LIKE '%\".$pieces[0].\"%')\n \n AND\n \n (n.firstname LIKE '%\".$pieces[1].\"%' OR\n n.middlename LIKE '%\".$pieces[1].\"%' OR\n n.lastname LIKE '%\".$pieces[1].\"%' OR\n n.suffix LIKE '%\".$pieces[1].\"%')\n \n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$pieces[0].\"%' OR\n n.middlename LIKE '%\".$pieces[0].\"%' OR\n n.lastname LIKE '%\".$pieces[0].\"%' OR\n n.suffix LIKE '%\".$pieces[0].\"%')\n \n AND\n\n (n.firstname LIKE '%\".$pieces[1].\"%' OR\n n.middlename LIKE '%\".$pieces[1].\"%' OR\n n.lastname LIKE '%\".$pieces[1].\"%' OR\n n.suffix LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (n.firstname LIKE '%\".$pieces[2].\"%' OR\n n.middlename LIKE '%\".$pieces[2].\"%' OR\n n.lastname LIKE '%\".$pieces[2].\"%' OR\n n.suffix LIKE '%\".$pieces[2].\"%')\n \n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$q.\"%' OR\n n.middlename LIKE '%\".$q.\"%' OR\n n.lastname LIKE '%\".$q.\"%' OR\n n.suffix LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction title_abstract_search($q)\n{\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = split(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$pieces[0].\"%' OR\n d.abstract LIKE '%\".$pieces[0].\"%')\n \n AND\n\n (d.title LIKE '%\".$pieces[1].\"%' OR\n d.abstract LIKE '%\".$pieces[1].\"%')\n \n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$pieces[0].\"%' OR\n d.abstract LIKE '%\".$pieces[0].\"%')\n \n AND\n\n (d.title LIKE '%\".$pieces[1].\"%' OR\n d.abstract LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (d.title LIKE '%\".$pieces[2].\"%' OR\n d.abstract LIKE '%\".$pieces[2].\"%')\n \n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$q.\"%' OR\n d.abstract LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction notes_search($q)\n{\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = split(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$pieces[0].\"%')\n \n AND\n\n (d.notes LIKE '%\".$pieces[1].\"%')\n \n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$pieces[0].\"%')\n \n AND\n\n (d.notes LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (d.notes LIKE '%\".$pieces[2].\"%')\n \n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction encode_linebreaks($bigtext)\n{\n # from http://us3.php.net/str_replace\n $order = array(\"\\r\\n\", \"\\n\", \"\\r\");\n $replace = '
';\n // Processes \\r\\n's first so they aren't converted twice.\n $with_breaks = str_replace($order, $replace, $bigtext);\n return $with_breaks;\n}\n\n# -------------------------------------------------------------------------------\nfunction get_logs($offset=\"0\")\n{\n# echo \"[$offset]\";\n $query = \"SELECT * FROM logs ORDER BY id DESC LIMIT 100\";\n if ($offset != \"\"){$query .= \" OFFSET $offset\";}\n $result = mysql_query($query) or die(mysql_error());\n\n# echo $query;\n $entries = array();\n $counter = 0;\n while ( $line = mysql_fetch_array($result)) {\n $counter++;\n $entries[$counter] = $line;\n }\n return $entries;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction get_dissertation_history($id)\n{\n $query = \"SELECT * FROM logs\n WHERE type='dissertation' AND message LIKE '$id %'\n ORDER BY id DESC\";\n $result = mysql_query($query) or die(mysql_error());\n\n# echo $query;\n $entries = array();\n $counter = 0;\n while ( $line = mysql_fetch_array($result)) {\n $counter++;\n $entries[$counter] = $line;\n }\n return $entries;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction find_all_people()\n{\n # return array of all people_ids in database (slow....)\n # all people\n $query = \"SELECT id as person_id FROM people\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $people[] = $line['person_id'];\n }\n return $people;\n}\n\n# -------------------------------------------------------------------------------\nfunction get_person_link($person_id)\n{\n\n $disciplines = find_disciplines();\n $person = find_person($person_id);\n\n $fullname = trim($person['firstname'].\" \".$person['middlename'].\" \".$person['lastname'].\" \".$person['suffix']);\n\n $dissertation = find_dissertation_by_person($person_id);\n $discipline = isset($dissertation['discipline_id']) ? $disciplines[$dissertation['discipline_id']] : \"\";\n \n $link = \"\".$fullname.\"\";\n\n return $link;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_orphans()\n{\n\n # finding people with no dissertation and no students\n\n # all people\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n\n WHERE\n p.preferred_name_id = n.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $people[$line['person_id']] = $line;\n# echo \" \".$line['person_id'].\"
\\n\";\n }\n \n echo \"people: \".count($people).\"
\\n\";\n\n # with dissertations only\n $query = \"SELECT\n p.id as person_id\n FROM\n people p, dissertations d\n WHERE\n d.person_id = p.id\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $with_dissertations[$line['person_id']] = $line;\n# echo \" \".$line['person_id'].\"
\\n\";\n }\n\n echo \"dissertations: \".count($with_dissertations).\"
\\n\";\n\n # all people - dissertations = teachers only\n $potentialmentors = array_key_diff($people,$with_dissertations);\n\n echo \"potential mentors: \".count($potentialmentors).\"
\\n\";\n\n # orphans = teachers who don't have students\n # get advisorships\n $query = \"SELECT person_id FROM advisorships\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $advisors[$line['person_id']] = $line;\n }\n echo \"advisors: \".count($advisors).\"
\\n\";\n # get committeeships\n $query = \"SELECT person_id FROM committeeships\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n $committeemembers[$line['person_id']] = $line;\n }\n echo \"committeemembers: \".count($committeemembers).\"
\\n\";\n # subtract advisorships from teachers\n $potentialmentors = array_key_diff($potentialmentors,$advisors);\n # subtract committeeships from remaining teachers\n $orphans = array_key_diff($potentialmentors,$committeemembers);\n echo \"orphans: \".count($orphans).\"
\\n\";\n\n return $orphans;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction is_orphan($person_id)\n{\n # confirm person exists\n $query = \"SELECT * FROM people WHERE id = '\".$person_id.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n $line = mysql_fetch_array($result);\n if (!$line['id']){echo \"not a person\";return 0;}\n # confirm no dissertation\n $query = \"SELECT * FROM dissertations WHERE person_id = '\".$person_id.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n echo \"found a dissertation\";\n return 0;\n }\n # confirm not a committeemember\n $query = \"SELECT * FROM committeeships WHERE person_id = '\".$person_id.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n echo \"found a committeeship\";\n return 0;\n }\n # confirm not an advisor\n $query = \"SELECT * FROM advisorships WHERE person_id = '\".$person_id.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n echo \"found an advisorship\";\n return 0;\n }\n return 1;\n}\n# -------------------------------------------------------------------------------\nfunction delete_person($person_id)\n{\n if (is_orphan($person_id))\n {\n $before = find_person($person_id);\n # delete all names\n $query = \"DELETE FROM names WHERE person_id = '\".$person_id.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n # delete the person\n $query = \"DELETE FROM people WHERE id = '\".$person_id.\"' LIMIT 1\";\n $result = mysql_query($query) or die(mysql_error());\n # log it\n mpact_logger(\"deleted person[\".$person_id.\"] (\".$before['fullname'].\")\");\n return 1;\n }\n else\n {\n action_box(\"Not an orphan - Cannot delete this person.\");\n return 0;\n }\n}\n# -------------------------------------------------------------------------------\nfunction remove_duplicate_names($person_id)\n{\n\n $names = array();\n $deleteme = array();\n\n\n $before = find_person($person_id);\n\n // get the preferred_name_id\n $query = \"SELECT preferred_name_id\n FROM people\n WHERE id = '\".$person_id.\"'\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n // get the full preferred_name\n $query = \"SELECT * FROM names\n WHERE\n id = '\".$preferred_name_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $fullname = \"\".$line['firstname'].\" \".$line['middlename'].\" \".$line['lastname'].\" \".$line['suffix'].\"\";\n $names[$fullname] = $line['id']; \n }\n\n // get the rest of the names for this person\n $query = \"SELECT * FROM names\n WHERE\n person_id = '\".$person_id.\"' AND\n id != '\".$preferred_name_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $fullname = \"\".$line['firstname'].\" \".$line['middlename'].\" \".$line['lastname'].\" \".$line['suffix'].\"\";\n if (isset($names[$fullname]))\n {\n $deleteme[] = $line['id'];\n }\n else\n {\n $names[$fullname] = $line['id']; \n }\n }\n\n // delete each deleteme id\n foreach ($deleteme as $one)\n {\n $query = \"DELETE FROM names\n WHERE\n id = '\".$one.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n }\n\n # log it\n mpact_logger(\"removed duplicate names for person[\".$person_id.\"] (\".$before['fullname'].\")\");\n\n}\n\n# -------------------------------------------------------------------------------\nfunction add_mentor($type,$student_id,$mentor_id)\n{\n $student = find_person($student_id);\n $mentor = find_person($mentor_id);\n $dissertation = find_dissertation_by_person($student_id);\n\n if ($type == \"A\")\n {\n # find existing advisors for this student\n $advisors = find_advisors_for_person($student_id);\n # if new/different - then add them to the student's dissertation\n if (in_array($mentor_id,$advisors))\n {\n # skip - already listed as advisor\n }\n else\n {\n $query = \"INSERT advisorships\n SET\n dissertation_id = '\".$dissertation['id'].\"',\n person_id = '\".$mentor_id.\"'\n \";\n# echo $query;\n $result = mysql_query($query) or die(mysql_error());\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"add advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n # delete existing dotgraphs - they'll need to be regenerated\n # has to happen after we add the advisor link itself\n delete_associated_dotgraphs($student_id);\n }\n }\n elseif ($type == \"C\")\n {\n # find existing committee members for this student\n $committee = find_committee_for_person($student_id);\n # if new/different - then add them to the student's dissertation \n if (in_array($mentor_id,$committee))\n {\n # skip - already on committee\n }\n else\n {\n $query = \"INSERT committeeships\n SET\n dissertation_id = '\".$dissertation['id'].\"',\n person_id = '\".$mentor_id.\"'\n \";\n# echo $query;\n $result = mysql_query($query) or die(mysql_error());\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"add committeeship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n }\n }\n else\n {\n # nothing\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction remove_mentor($type,$student_id,$mentor_id)\n{\n $dissertation = find_dissertation_by_person($student_id);\n\n $student = find_person($student_id);\n $mentor = find_person($mentor_id);\n\n if ($type == \"A\")\n {\n # find dissertation id\n $dissertation = find_dissertation_by_person($student_id);\n # find existing advisors for this student\n $advisors = find_advisors_for_person($student_id);\n # if found in db, remove them\n if (!in_array($mentor_id,$advisors))\n {\n echo \"not an advisor for this student\";\n return 0;\n }\n else\n {\n # delete existing dotgraphs - they'll need to be regenerated\n # has to happen before we delete the advisor link itself\n delete_associated_dotgraphs($student_id);\n # delete the advisorship\n $query = \"DELETE FROM advisorships\n WHERE\n person_id = '\".$mentor_id.\"' AND\n dissertation_id = '\".$dissertation['id'].\"'\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"remove advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n return 1;\n }\n }\n elseif ($type == \"C\")\n {\n # find dissertation id\n $dissertation = find_dissertation_by_person($student_id);\n # find existing committee members for this student\n $committee = find_committee_for_person($student_id);\n # if found in db, remove them \n if (!in_array($mentor_id,$committee))\n {\n echo \"not on committee for this student\";\n return 0;\n }\n else\n {\n $query = \"DELETE FROM committeeships\n WHERE\n person_id = '\".$mentor_id.\"' AND\n dissertation_id = '\".$dissertation['id'].\"'\n LIMIT 1\n \";\n $result = mysql_query($query) or die(mysql_error());\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"remove advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n return 1;\n }\n }\n else\n {\n echo \"has to be A or C, dude\";\n return 0;\n }\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_all_people_for_selectbox($with_dissertation=\"0\")\n{\n if ($with_dissertation == \"0\")\n {\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n\n WHERE\n p.preferred_name_id = n.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \"; \n }\n else\n {\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n, dissertations d\n WHERE\n p.preferred_name_id = n.id AND\n d.person_id = p.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \";\n }\n // echo $query;\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $people[$line['person_id']] = $line;\n }\n\n return $people;\n}\n\n# -------------------------------------------------------------------------------\nfunction merge_two_people($from_id, $into_id)\n{\n\n $from_person = find_person($from_id);\n $into_person = find_person($into_id);\n \n\n $query = \"UPDATE advisorships\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n $query = \"UPDATE dissertations\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n $query = \"UPDATE committeeships\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n $query = \"UPDATE urls\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n // move each 'from' name to the 'into' person\n \n $query = \"UPDATE names\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n // remove any new duplicates in the names table\n \n remove_duplicate_names($into_person['id']); \n\n // remove 'from' person from the database\n \n $query = \"DELETE FROM people\n WHERE\n id = '\".$from_person['id'].\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n # log it\n mpact_logger(\"merged two people [\".$from_id.\"] (\".$from_person['fullname'].\") and [\".$into_id.\"] (\".$into_person['fullname'].\")\");\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_aliases($person_id)\n{\n\n $query = \"SELECT preferred_name_id\n FROM people\n WHERE id = '\".$person_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n\n $names = array();\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, n.id\n FROM\n names n\n WHERE\n n.person_id = '\".$person_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $names[$line['id']] = $line;\n }\n\n unset($names[$preferred_name_id]);\n \n return $names;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_person($person_id)\n{\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, p.degree,\n p.id, p.preferred_name_id\n FROM\n names n, people p\n WHERE\n p.preferred_name_id = n.id AND\n p.id = \".$person_id.\"\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $person = $line;\n $person['fullname'] = $person['firstname'];\n if ($person['middlename'] != \"\"){$person['fullname'] .= \" \".$person['middlename'];}\n if ($person['lastname'] != \"\"){$person['fullname'] .= \" \".$person['lastname'];}\n if ($person['suffix'] != \"\"){$person['fullname'] .= \" \".$person['suffix'];}\n }\n\n return $person;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_url($url_id)\n{\n\n $url_id = intval($url_id);\n $query = \"SELECT\n u.id, u.url, u.description, u.updated_at, u.person_id\n FROM\n urls u\n WHERE\n u.id = '\".$url_id.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $url = $line;\n }\n\n return $url;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_urls_by_person($person_id)\n{\n\n $person_id = intval($person_id);\n $query = \"SELECT\n u.id, u.url, u.description, u.updated_at, u.person_id\n FROM\n urls u\n WHERE\n u.person_id = '\".$person_id.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $urls = array();\n while ( $line = mysql_fetch_array($result)) {\n $urls[$line['id']] = $line;\n }\n\n return $urls;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dissertation($dissertation_id)\n{\n\n $dissertation_id = intval($dissertation_id);\n $query = \"SELECT\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n WHERE\n d.id = '\".$dissertation_id.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertation = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertation = $line;\n }\n\n return $dissertation;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dissertation_by_person($person_id)\n{\n\n $person_id = intval($person_id);\n $query = \"SELECT\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n WHERE\n d.person_id = '\".$person_id.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n $dissertation = array();\n while ( $line = mysql_fetch_array($result)) {\n $dissertation = $line;\n }\n\n return $dissertation;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_name($name_id)\n{\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix\n FROM\n names n\n WHERE\n n.id = \".$name_id.\"\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $name = $line;\n $name['fullname'] = $name['firstname'];\n if ($name['middlename'] != \"\"){$name['fullname'] .= \" \".$name['middlename'];}\n if ($name['lastname'] != \"\"){$name['fullname'] .= \" \".$name['lastname'];}\n if ($name['suffix'] != \"\"){$name['fullname'] .= \" \".$name['suffix'];}\n }\n\n return $name;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline($discipline_id)\n{\n $discipline_id = intval($discipline_id);\n $query = \"SELECT\n d.title, d.description\n FROM\n disciplines d\n WHERE\n d.id = \".$discipline_id.\"\n \";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result)) {\n $discipline = $line;\n }\n\n return $discipline;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_ancestors_for_group($groupofpeople)\n{\n $originalgroup = $groupofpeople;\n // find advisors, and if they're new, add them to the list and recurse\n foreach ($originalgroup as $person)\n {\n $advisors = find_advisors_for_person($person);\n foreach ($advisors as $one)\n {\n $groupofpeople[] = $one;\n }\n }\n $groupofpeople = array_unique($groupofpeople);\n if (count(array_diff($groupofpeople,$originalgroup)) > 0)\n {\n return find_ancestors_for_group($groupofpeople);\n }\n else\n {\n return $originalgroup;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_descendents_for_group($groupofpeople)\n{\n $originalgroup = $groupofpeople;\n // find descendents, and if they're new, add them to the list and recurse\n foreach ($originalgroup as $person)\n {\n $advisees = find_advisorships_under_person($person);\n foreach ($advisees as $one)\n {\n $groupofpeople[] = $one;\n }\n }\n $groupofpeople = array_unique($groupofpeople);\n if (count(array_diff($groupofpeople,$originalgroup)) > 0)\n {\n return find_descendents_for_group($groupofpeople);\n }\n else\n {\n return $originalgroup;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction T_score($person)\n{\n # total number of descendants (nodes) in a person's tree\n $group = array($person);\n $total = count(find_descendents_for_group($group)); # including self\n $descendents = $total - 1; # minus self\n return $descendents;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_mpact_score($person,$score_type)\n{\n $query = \"SELECT $score_type as score FROM people WHERE id='$person'\";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n return $score;\n}\n\n# -------------------------------------------------------------------------------\nfunction FMI_score($person)\n{\n $FMI_score = count(find_advisorships_under_person($person));\n# print \"person $person -- fmi $FMI_score
\";\n $committeeships = find_committeeships_under_person($person);\n foreach ($committeeships as $one)\n {\n $numA = count(find_advisors_for_person($one));\n# echo \" - #A [$numA] ----
\";\n $numC = count(find_committee_for_person($one));\n# echo \"#C [$numC] ---- \\n\";\n $FMI_score += 1/($numA + $numC);\n# echo \"
\";\n }\n // echo \"fractional mentorship, inclusive (FMI = A + eachC(1/(#A+#C)) )
\\n\";\n return round($FMI_score,3);\n}\n\n# -------------------------------------------------------------------------------\nfunction FME_score($person)\n{\n $FME_score = count(find_advisorships_under_person($person));\n# print \"person $person -- fme $FME_score
\";\n $committeeships = find_committeeships_under_person($person);\n foreach ($committeeships as $one)\n {\n $numC = count(find_committee_for_person($one));\n# echo \"#C [$numC] ---- \\n\";\n $FME_score += 1/($numC);\n# echo \"
\";\n }\n // echo \"fractional mentorship, inclusive (FMI = A + eachC(1/(#A+#C)) )
\\n\";\n return round($FME_score,3);\n}\n\n# -------------------------------------------------------------------------------\nfunction TA_score($person)\n{\n # total number of descendants who have advised students themselves\n $without_students = array();\n $descendents = find_descendents_for_group(array($person)); # including self\n foreach ($descendents as $d)\n {\n if (count(find_descendents_for_group(array($d))) == 1)\n {\n $without_students[] = $d;\n }\n }\n $descendents_who_advised = array_diff($descendents,$without_students); # including self\n return max(count($descendents_who_advised) - 1,0); # minus self\n}\n\n# -------------------------------------------------------------------------------\nfunction W_score($person)\n{\n # should handle multigenerational advisorships correctly...\n\n # return the max of the widths of each generation of descendents\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n# print \"$gencount <-- gen
\";\n# print count($advisees).\" advisees - \";\n# print_r($advisees);\n# print \"
\";\n# print \"
\";\n# print count($remaining).\" remaining - \";\n# print_r($remaining);\n# print \"
\";\n# print \"
\";\n while (count($remaining) > 0)\n {\n $gencount++;\n# print \"$gencount <-- gen
\";\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n# print count($advisees).\" advisees - \";\n# print_r($advisees);\n# print \"
\";\n# print \"
\";\n# print count($remaining).\" remaining - \";\n# print_r($remaining);\n# print \"
\";\n# print \"
\";\n }\n# print_r($gen_widths);\n return max($gen_widths);\n}\n\n# -------------------------------------------------------------------------------\nfunction TD_score($person)\n{\n # there is currently a bug in this implementation\n # if a student has two advisors, and they, themselves are related by mentorship\n # this algorithm currently counts gen_width based on advisee count only\n # since $td is calculated based on gen_width values, TD will be missing data\n # A is advisor to B and C\n # B is advisor to C\n # A should have a TD score of 2 (full credit for both advisees)\n # upon further reflection, perhaps this is working correctly, by accident\n\n # return the decayed score\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n while (count($remaining) > 0)\n {\n $gencount++;\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n }\n# print_r($gen_widths);\n $td = 0;\n foreach($gen_widths as $one => $two)\n {\n $num = $two;\n $den = (pow(2,($one-1)));\n $f = $num/$den;\n# print \"$num/$den = $f
\";\n $td = $td + $f;\n }\n return $td;\n}\n\n# -------------------------------------------------------------------------------\nfunction G_score($person)\n{\n # there is currently a bug in this implementation\n # if a student has two advisors, and they, themselves are related by mentorship\n # this algorithm currently misses a generation in the calculation of G\n # A is advisor to B and C\n # B is advisor to C\n # A should have a G score of 2, but will only be calculated a 1\n\n\n # return the number of generations of descendents\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n while (count($remaining) > 0)\n {\n $gencount++;\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n }\n if ($gen_widths[1] == 0)\n {\n return 0;\n }\n else\n {\n return count($gen_widths);\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction advisees_of_group($group)\n{\n # W helper function\n $advisees = array();\n foreach ($group as $one)\n {\n $advisees[] = find_advisorships_under_person($one);\n }\n $advisees = flattenArray($advisees);\n# print_r($advisees);\n# print \" <-- advisees of group
\";\n return $advisees;\n}\n\n# -------------------------------------------------------------------------------\nfunction flattenArray($array) \n{\n $flatArray = array();\n foreach( $array as $subElement ) {\n if( is_array($subElement) )\n $flatArray = array_merge($flatArray, flattenArray($subElement));\n else\n $flatArray[] = $subElement;\n }\n return $flatArray;\n}\n\n# -------------------------------------------------------------------------------\nfunction calculate_scores($person_id)\n{\n $A_score = count(find_advisorships_under_person($person_id));\n $C_score = count(find_committeeships_under_person($person_id));\n $AC_score = $A_score + $C_score;\n $G_score = G_score($person_id);\n $W_score = W_score($person_id);\n $T_score = T_score($person_id);\n $TA_score = TA_score($person_id);\n $TD_score = TD_score($person_id);\n $FMI_score = FMI_score($person_id);\n $FME_score = FME_score($person_id);\n\n $query = \"UPDATE people\n SET\n a_score = '$A_score',\n c_score = '$C_score',\n ac_score = '$AC_score',\n g_score = '$G_score',\n w_score = '$W_score',\n t_score = '$T_score',\n ta_score = '$TA_score',\n td_score = '$TD_score',\n fmi_score = '$FMI_score',\n fme_score = '$FME_score',\n scores_calculated = now()\n WHERE\n id = \".$person_id.\"\n \";\n $result = mysql_query($query) or die(mysql_error());\n}\n\n# -------------------------------------------------------------------------------\nfunction mpact_scores($passed_person)\n{\n $glossaryterms = find_glossaryterms();\n\n $query = \"SELECT\n a_score, c_score, ac_score, g_score, w_score,\n t_score, ta_score, td_score, fmi_score, fme_score,\n scores_calculated\n FROM people\n WHERE id = \".$passed_person.\"\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result)) {\n extract($line);\n }\n \n $mpact['A'] = $a_score;\n $mpact['C'] = $c_score;\n $mpact['AC'] = $ac_score;\n $scores_output = \"A = $a_score
\\n\";\n $scores_output .= \"C = $c_score
\\n\";\n $scores_output .= \"A+C = $ac_score
\\n\";\n\n $mpact['FMI'] = $fmi_score;\n $mpact['FME'] = $fme_score;\n $FMIdivFULL = ($ac_score>0) ? $fmi_score / $ac_score : 0;\n $FMIdivFULL = round($FMIdivFULL,3);\n $mpact['FMIdivFULL'] = $FMIdivFULL;\n $FMEdivFULL = ($ac_score>0) ? $fme_score / $ac_score : 0;\n $FMEdivFULL = round($FMEdivFULL,3);\n $mpact['FMEdivFULL'] = $FMEdivFULL;\n if (is_admin())\n {\n $scores_output .= \"FMI = $fmi_score
\\n\";\n $scores_output .= \"FME = $fme_score
\\n\";\n $scores_output .= \"FMI/(A+C) = $FMIdivFULL
\\n\";\n $scores_output .= \"FME/(A+C) = $FMEdivFULL
\\n\";\n }\n\n $mpact['T'] = $t_score;\n $scores_output .= \"T = $t_score
\\n\";\n $mpact['G'] = $g_score;\n $scores_output .= \"G = $g_score
\\n\";\n $mpact['W'] = $w_score;\n $scores_output .= \"W = $w_score
\\n\";\n $mpact['TD'] = $td_score;\n $scores_output .= \"D']].\"\\\">TD = $td_score
\\n\";\n $mpact['TA'] = $ta_score;\n $scores_output .= \"A']].\"\\\">TA = $ta_score
\\n\";\n $scores_output .= \"calculated $scores_calculated
\\n\";\n $mpact['output'] = $scores_output;\n\n return $mpact;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_advisors_for_person($person_id)\n{\n\n // get person's own advisor(s)\n\n $listing = array();\n\n\n $query = \"SELECT a.person_id\n FROM\n dissertations d,\n advisorships a\n WHERE\n d.person_id = \".$person_id.\" AND\n a.dissertation_id = d.id\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_committee_for_person($person_id)\n{\n\n // get person's own committee member(s)\n\n $listing = array();\n\n $query = \"SELECT c.person_id\n FROM\n dissertations d,\n committeeships c\n WHERE\n d.person_id = \".$person_id.\" AND\n c.dissertation_id = d.id\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_advisorships_under_person($person_id)\n{\n\n // get person's advisorships (below)\n\n $listing = array();\n\n $query = \"SELECT d.person_id\n FROM\n dissertations d,\n advisorships a\n WHERE\n a.person_id = \".$person_id.\" AND\n a.dissertation_id = d.id\n ORDER BY\n d.completedyear ASC\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_committeeships_under_person($person_id)\n{\n\n // get person's committeeships (below)\n\n $listing = array();\n\n $query = \"SELECT d.person_id\n FROM\n dissertations d,\n committeeships c\n WHERE\n c.person_id = '\".$person_id.\"' AND\n c.dissertation_id = d.id\n ORDER BY\n d.completedyear\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction set_preferred_name($person_id,$name_id)\n{\n\n # delete current family tree of dotgraphs\n delete_associated_dotgraphs($person_id);\n\n # set it\n\n $listing = array();\n\n $before = find_person($person_id);\n\n $query = \"UPDATE people\n SET\n preferred_name_id = '\".$name_id.\"'\n WHERE\n id = '\".$person_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n $after = find_person($person_id);\n\n # log it\n mpact_logger(\"set preferred name for person[\".$person_id.\"] from name[\".$before['preferred_name_id'].\"] (\".$before['fullname'].\") to name[\".$name_id.\"] (\".$after['fullname'].\")\");\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_profs_at_dept($school_id,$discipline_id)\n{\n\n $dissertations = array();\n $listing = array();\n $advisors = array();\n $committeemembers = array();\n\n // get all dissertations at this dept\n\n $query = \"SELECT d.id\n FROM dissertations d, schools s\n WHERE\n d.school_id = s.id AND\n s.id = '\".$school_id.\"' AND\n d.discipline_id = '\".$discipline_id.\"'\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $dissertations[] = $line['id'];\n }\n\n if (count($dissertations)>0)\n {\n // get all advisors for these dissertations\n\n $query = \"SELECT a.person_id\n FROM dissertations d, advisorships a\n WHERE\n a.dissertation_id IN (\";\n $query .= implode(\", \", $dissertations);\n $query .= \") AND\n a.dissertation_id = d.id\";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $advisors[$line['person_id']] = $line['person_id'];\n }\n \n // get all committeemembers for these dissertations\n\n $query = \"SELECT c.person_id\n FROM dissertations d, committeeships c\n WHERE\n c.dissertation_id IN (\";\n $query .= implode(\", \", $dissertations);\n $query .= \") AND\n c.dissertation_id = d.id\";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $committeemembers[$line['person_id']] = $line['person_id'];\n }\n }\n\n // return the combined list (uniquified when combined)\n\n// echo \"\\na - \".count($advisors);\n// echo \"\\nc - \".count($committeemembers);\n $listing = $advisors + $committeemembers;\n// echo \"\\ncombined before - \".count($listing);\n return $listing;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_profs_at_dept($school_id,$discipline_id)\n{\n $query = \"SELECT professors\n FROM profs_at_dept\n WHERE\n school_id = '$school_id' AND\n discipline_id = '$discipline_id'\n \";\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result))\n {\n $listing = unserialize($line['professors']);\n }\n return $listing;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_disciplines($school_id=null)\n{\n\n $disciplines = array();\n if ($school_id)\n {\n // get all disciplines at this school\n $query = \"SELECT d.id, d.title\n FROM\n disciplines d, schools s, dissertations diss\n WHERE\n diss.school_id = s.id AND\n diss.discipline_id = d.id AND\n s.id = '$school_id'\n ORDER BY\n d.title\n \";\n }\n else\n {\n $query = \"SELECT id, title\n FROM\n disciplines d\n ORDER BY\n title\n \";\n }\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $disciplines[$line['id']] = $line['title'];\n }\n\n if (isset($disciplines))\n {\n return $disciplines;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction is_duplicate_discipline($title)\n{\n $disciplinefound = 0;\n\n $query = \"SELECT id FROM disciplines WHERE title = '$title'\";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $disciplinefound = $line['id'];\n }\n\n if ($disciplinefound > 0){\n return true;\n }\n\n return false;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_empty_discipline($discipline_id)\n{\n $query = \"SELECT count(*) as howmany FROM dissertations WHERE discipline_id = $discipline_id\";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n extract($line);\n }\n\n if ($howmany > 0){\n return false;\n }\n\n return true;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_duplicate_school($fullname)\n{\n $schoolfound = 0;\n\n $query = \"SELECT id FROM schools WHERE fullname = '$fullname'\";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $schoolfound = $line['id'];\n }\n\n if ($schoolfound > 0){\n return true;\n }\n\n return false;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_empty_school($school_id)\n{\n $query = \"SELECT count(*) as howmany FROM dissertations WHERE school_id = $school_id\";\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n extract($line);\n }\n\n if ($howmany > 0){\n return false;\n }\n\n return true;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline_counts()\n{\n \n // get all discipline counts from the database\n\n $disciplinecounts = array();\n \n $query = \"SELECT discipline_id, count(*) as disciplinecount\n FROM dissertations\n GROUP BY discipline_id\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $disciplinecounts[$line['discipline_id']] = $line['disciplinecount'];\n }\n\n if (isset($disciplinecounts))\n {\n return $disciplinecounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline_statuses($discipline_id)\n{\n\n // get status counts for this discipline\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n \n $query = \"SELECT status, count(*) as disciplinecount\n FROM dissertations\n WHERE discipline_id='$discipline_id'\n GROUP BY status\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disciplinecount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dept_counts($school_id,$discipline_id)\n{\n \n // get all department counts from the database\n\n $deptcounts = array();\n \n $query = \"SELECT discipline_id, count(*) as disciplinecount\n FROM dissertations\n GROUP BY discipline_id\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $deptcounts[$line['discipline_id']] = $line['disciplinecount'];\n }\n\n if (isset($deptcounts))\n {\n return $deptcounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dept_statuses($school_id,$discipline_id)\n{\n\n // get status counts for this school in this discipline\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n \n $query = \"SELECT status, count(*) as disciplinecount\n FROM dissertations\n WHERE\n discipline_id='$discipline_id' AND\n school_id='$school_id'\n GROUP BY status\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disciplinecount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_schools($discipline_id=null)\n{\n // get all schools in a discipline (or all disciplines)\n $schools = array();\n if ($discipline_id)\n {\n // look up schools at dissertations in this discipline\n $query = \"SELECT s.id, s.fullname\n FROM\n dissertations d, schools s\n WHERE\n d.school_id = s.id AND\n d.discipline_id = '$discipline_id'\n GROUP BY\n d.school_id\n ORDER BY\n s.fullname ASC\n \";\n }\n else\n {\n $query = \"SELECT id, fullname\n FROM\n schools s\n ORDER BY fullname\n \";\n }\n $result = mysql_query($query) or die(mysql_error());\n while ( $line = mysql_fetch_array($result))\n {\n $schools[$line['id']] = $line['fullname'];\n }\n\n if (isset($schools))\n {\n return $schools;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school_counts()\n{\n \n // get all school dissertation counts from the database\n\n $schoolcounts = array();\n \n $query = \"SELECT school_id, count(*) as disscount\n FROM dissertations\n GROUP BY school_id\n \";\n \n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $schoolcounts[$line['school_id']] = $line['disscount'];\n }\n\n if (isset($schoolcounts))\n {\n return $schoolcounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school_statuses($school_id)\n{\n\n // get status counts for this school\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n \n $query = \"SELECT status, count(*) as disscount\n FROM dissertations\n WHERE school_id='$school_id'\n GROUP BY status\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n\n while ( $line = mysql_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disscount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction find_persons_school($passed_person)\n{\n\n // get person's degree school\n\n $query = \"SELECT\n d.id as dissertation_id,\n d.completedyear,\n d.title,\n d.abstract,\n s.fullname,\n s.country,\n s.id as schoolid\n FROM\n dissertations d,\n schools s\n WHERE\n d.person_id = \".$passed_person.\" AND\n d.school_id = s.id\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n $thisperson['dissertation_id'] = $line['dissertation_id'];\n $thisperson['completedyear'] = $line['completedyear'];\n $thisperson['title'] = $line['title'];\n $thisperson['abstract'] = $line['abstract'];\n $thisperson['country'] = $line['country'];\n $thisperson['school'] = $line['fullname'];\n $thisperson['schoolid'] = $line['schoolid'];\n }\n\n if (isset($thisperson))\n {\n return $thisperson;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school($school_id)\n{\n\n // get school\n\n $query = \"SELECT\n s.fullname,\n s.country\n FROM\n schools s\n WHERE\n s.id = \".$school_id.\"\n \";\n\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n $school['country'] = $line['country'];\n $school['fullname'] = $line['fullname'];\n }\n\n if (isset($school))\n {\n return $school;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction get_environment_info()\n{\n $host_info = array();\n $hostname = $_SERVER['SERVER_NAME'];\n if ($hostname == \"\"){$hostname = exec(hostname);}\n# echo \"hostname = [$hostname]
\";\n if ($hostname == \"www.ibiblio.org\" || $hostname == \"www-dev.ibiblio.org\" || $hostname == \"login1.ibiblio.org\")\n {\n # the main install on ibiblio\n $host_info['hostname'] = \"ibiblio\";\n $host_info['ownername'] = \"mpact\";\n $host_info['dotlocation'] = \"/export/sunsite/users/mpact/terrelllocal/bin/dot\";\n $host_info['appdir'] = \"/public/html/mpact\";\n $host_info['webdir'] = \"http://www.ibiblio.org/mpact\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"Times-Roman\";\n }\n else if ($hostname == \"trel.dyndns.org\")\n {\n # my local development machine\n $host_info['hostname'] = \"home\";\n $host_info['ownername'] = \"trel\";\n $host_info['dotlocation'] = \"/sw/bin/dot\";\n $host_info['appdir'] = \"/Library/WebServer/Documents/MPACTlocal/app\";\n $host_info['webdir'] = \"http://trel.dyndns.org:9000/mpactlocal/app\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"cour\";\n }\n else if ($hostname == \"localhost.com\" || $hostname == \"trelpancake\")\n {\n # my laptop\n $host_info['hostname'] = \"laptop\";\n $host_info['ownername'] = \"trel\";\n $host_info['dotlocation'] = \"/opt/local/bin/dot\";\n $host_info['appdir'] = \"/Users/trel/Sites/MPACT\";\n $host_info['webdir'] = \"http://localhost.com/~trel/MPACT\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"cour\";\n }\n else\n {\n # unknown host\n #exit;\n }\n\n return $host_info;\n}\n\n# -------------------------------------------------------------------------------\nfunction delete_associated_dotgraphs($passed_person)\n{\n $host_info = get_environment_info();\n $group = array($passed_person);\n $ancestors = find_ancestors_for_group($group);\n $descendents = find_descendents_for_group($group);\n $entire_family_tree = array_unique($ancestors + $descendents);\n foreach ($entire_family_tree as $one)\n {\n # set the filenames\n $dotfilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.dot\";\n $imagefilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.\".$host_info['dotfiletype'];\n $imagemapfilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.map\";\n # delete each if they exist\n if (file_exists($dotfilename))\n {\n `rm $dotfilename`;\n }\n if (file_exists($imagefilename))\n {\n `rm $imagefilename`;\n }\n if (file_exists($imagemapfilename))\n {\n `rm $imagemapfilename`;\n }\n # mark as 'dirty' so cronjob can recreate images\n mark_record_as_dirty($one);\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction mark_record_as_dirty($passed_person)\n{\n # mark database record for this person as dirty\n # a cronjob will pick these up and regenerate their dotgraphs\n # gets around permission issues on the server if necessary\n $query = \"UPDATE people SET regenerate_dotgraph = '1' WHERE id = '\".$passed_person.\"'\";\n $result = mysql_query($query) or die(mysql_error());\n}\n\n# -------------------------------------------------------------------------------\nfunction narray_slice($array, $offset, $length) {\n # http://us3.php.net/manual/en/function.array-slice.php#73882\n\n //Check if this version already supports it\n if (str_replace('.', '', PHP_VERSION) >= 502)\n return array_slice($array, $offset, $length, true);\n\n foreach ($array as $key => $value) {\n\n if ($a >= $offset && $a - $offset <= $length)\n $output_array[$key] = $value;\n $a++;\n\n }\n return $output_array;\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_dotfile($passed_person){\n $a = find_person($passed_person);\n if ($a == null)\n {\n return 0;\n }\n else\n {\n $dotfilecontents = \"\";\n $dotfilecontents .= \"digraph familytree\\n\";\n $dotfilecontents .= \"{\\n\";\n $dotfilecontents .= \"rankdir=\\\"LR\\\"\\n\";\n $dotfilecontents .= \"node [fontname = Times, fontsize=10, shape = rect, height=.15]\\n\";\n # ancestors\n $upgroup = array();\n $upgroup[] = $passed_person;\n $ancestors = find_ancestors_for_group($upgroup);\n foreach ($ancestors as $one)\n {\n $person = find_person($one);\n $dotfilecontents .= \"$one [label = \\\"\".$person['fullname'].\"\\\" URL=\\\"mpact.php?op=show_tree&id=\".$one.\"\\\"];\\n\";\n $advisors = find_advisors_for_person($one);\n foreach ($advisors as $adv)\n {\n $dotfilecontents .= \"$adv -> $one;\\n\";\n }\n }\n # descendents\n $downgroup = array();\n $downgroup[] = $passed_person;\n $descendents = find_descendents_for_group($downgroup);\n foreach ($descendents as $one)\n {\n $person = find_person($one);\n $dotfilecontents .= \"$one [label = \\\"\".$person['fullname'].\"\\\" URL=\\\"mpact.php?op=show_tree&id=\".$one.\"\\\"\";\n if ($one == $passed_person){\n $dotfilecontents .= \" color=\\\"red\\\" style=\\\"filled\\\" fillcolor=\\\"grey\\\"\";\n }\n $dotfilecontents .= \"];\\n\";\n $advisees = find_advisorships_under_person($one);\n foreach ($advisees as $adv)\n {\n $dotfilecontents .= \"$one -> $adv;\\n\";\n }\n }\n $dotfilecontents .= \"}\\n\";\n\n return $dotfilecontents;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_tree_dotgraph($passed_person)\n{\n $person = $passed_person;\n $host_info = get_environment_info();\n if (isset($host_info['appdir']))\n {\n $webfilename = generate_dotgraph($person);\n if ($webfilename == \"marked_as_dirty\"){\n echo \"generating graph, please reload\";\n }\n else{\n echo \"\\\"Directed
\";\n }\n }\n else\n {\n echo \"graphics libraries are not configured\";\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_dotgraph($passed_person, $forcenew=\"no\")\n{\n $person = $passed_person;\n $host_info = get_environment_info();\n# print_r($host_info);\n $appcache = $host_info['appdir'].\"/\".$host_info['dotcachedir'];\n $webcache = $host_info['webdir'].\"/\".$host_info['dotcachedir'];\n $appfilename = \"$appcache/$person.\".$host_info['dotfiletype'];\n# echo \"appfilename = $appfilename
\\n\";\n $dotfilename = \"$appcache/$person.dot\";\n# echo \"dotfilename = $dotfilename
\\n\";\n $webfilename = \"$webcache/$person.\".$host_info['dotfiletype'];\n# echo \"webfilename = $webfilename
\\n\";\n $appimagemap = \"$appcache/$person.map\";\n# echo \"appimagemap = $appimagemap
\\n\";\n\n if (!file_exists($appfilename)) {\n # assumption is that the cachedir exists... (run setupmpact.sh)\n # generate dotfile\n if (!file_exists($dotfilename) or $forcenew == \"force\") {\n# print \" - creating dotfile...\\n\";\n $dotfilecontents = generate_dotfile($person);\n $fh = fopen($dotfilename, 'w');\n fwrite($fh, $dotfilecontents);\n fclose($fh);\n exec(\"chmod 666 $dotfilename\");\n }\n # generate graph\n $getandgenerategraph = \"/bin/cat $dotfilename | \".$host_info['dotlocation'].\" -Nfontname=\".$host_info['dotfontface'].\" -Gcharset=latin1 -Tcmapx -o$appimagemap -T\".$host_info['dotfiletype'].\" -o$appfilename 2>&1\";\n# echo \"getandgenerategraph = $getandgenerategraph
\";\n exec($getandgenerategraph);\n exec(\"chmod 666 $appimagemap\");\n exec(\"chmod 666 $appfilename\");\n if (!file_exists($appfilename)) {\n # mark as dirty if it didn't work\n mark_record_as_dirty($person);\n return \"marked_as_dirty\";\n }\n }\n else\n {\n# echo \"SHOWING CACHED COPY
\";\n }\n\n return $webfilename;\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_graph($passed_person)\n{\n if (!$passed_person){action_box(\"No ID given.\");}\n\n $person = $passed_person;\n $host_info = get_environment_info();\n if (isset($host_info['appdir']))\n {\n $appcache = $host_info['appdir'].\"/\".$host_info['dotcachedir'];\n $webcache = $host_info['webdir'].\"/\".$host_info['dotcachedir'];\n $appfilename = \"$appcache/$person.\".$host_info['dotfiletype'];\n #echo \"appfilename = $appfilename
\";\n $webfilename = \"$webcache/$person.\".$host_info['dotfiletype'];\n #echo \"webfilename = $webfilename
\";\n $appimagemap = \"$appcache/$person.map\";\n #echo \"appimagemap = $appimagemap
\";\n\n\n echo \"\";\n echo file_get_contents($appimagemap);\n }\n else\n {\n echo \"graphics libraries are not configured\";\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_tree($passed_person)\n{\n GLOBAL $statuscodes;\n GLOBAL $inspectioncodes;\n\n // shows a person\n\n if (!$passed_person){action_box(\"No ID given.\");}\n else\n {\n $personcount = 0;\n $thisperson = array();\n $dissertation = array();\n\n // get person's preferred name\n\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, p.degree\n FROM\n names n, people p\n WHERE\n p.preferred_name_id = n.id AND\n p.id = '\".$passed_person.\"'\n \";\n $result = mysql_query($query) or die(mysql_error());\n \n while ( $line = mysql_fetch_array($result)) {\n $thisperson['firstname'] = $line['firstname'];\n $thisperson['middlename'] = $line['middlename'];\n $thisperson['lastname'] = $line['lastname'];\n $thisperson['suffix'] = $line['suffix'];\n $thisperson['degree'] = $line['degree'];\n $personcount++;\n }\n\n $schoolinfo = find_persons_school($passed_person);\n $thisperson['dissertation_id'] = $schoolinfo['dissertation_id'];\n $thisperson['completedyear'] = $schoolinfo['completedyear'];\n $thisperson['country'] = $schoolinfo['country'];\n $thisperson['school'] = $schoolinfo['school'];\n $thisperson['schoolid'] = $schoolinfo['schoolid'];\n\n if ($thisperson['dissertation_id'] == \"\")\n {\n $thisperson['status'] = \"\";\n $thisperson['notes'] = \"\";\n $thisperson['title'] = \"N/A\";\n $thisperson['abstract'] = \"N/A\";\n $thisperson['abstract_html'] = \"N/A\";\n }\n else\n {\n $dissertation = find_dissertation($thisperson['dissertation_id']);\n $thisperson['status'] = $dissertation['status'];\n $thisperson['notes'] = $dissertation['notes'];\n $thisperson['discipline_id'] = $dissertation['discipline_id'];\n $thisperson['title'] = $dissertation['title'];\n $thisperson['abstract'] = $dissertation['abstract'];\n $thisperson['abstract_html'] = encode_linebreaks($dissertation['abstract']);\n if ($thisperson['title'] == \"\") { $thisperson['title'] = \"N/A\";}\n if ($thisperson['abstract'] == \"\")\n {\n $thisperson['abstract'] = \"N/A\";\n $thisperson['abstract_html'] = \"N/A\";\n }\n }\n\n $thisperson['advisors'] = find_advisors_for_person($passed_person);\n $thisperson['cmembers'] = find_committee_for_person($passed_person);\n $thisperson['advisorships'] = find_advisorships_under_person($passed_person);\n $thisperson['committeeships'] = find_committeeships_under_person($passed_person);\n\n\n if ($personcount < 1)\n {\n action_box(\"Person \".$passed_person.\" Not Found\");\n }\n else\n {\n\n echo \"
\\n\";\n\n # Name / Aliases\n $count = 0;\n $printme = \"\";\n $fullname = $thisperson['firstname'].\" \".$thisperson['middlename'].\" \".$thisperson['lastname'].\" \".$thisperson['suffix'];\n $printme .= \"

Dissertation Information for $fullname

\";\n $printme .= \"

\";\n if (is_admin())\n {\n if (isset($thisperson['completedyear']))\n {\n $printme .= \" (Edit)\";\n }\n else\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n $printme .= \"
\\n\";\n }\n $printme .= \"

\";\n $printme .= \"

\";\n $printme .= \"NAME: \";\n if (is_admin())\n {\n $printme .= \"(Add)\";\n }\n $printme .= \"
\";\n $printme .= \" - \";\n $printme .= get_person_link($passed_person);\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n $printme .= \"
\\n\";\n\n $aliases = 0;\n foreach (find_aliases($passed_person) as $one)\n {\n $printme .= \" - (Alias) \";\n $printme .= $one['firstname'].\" \";\n $printme .= $one['middlename'].\" \";\n $printme .= $one['lastname'].\" \";\n $printme .= $one['suffix'].\" \";\n if (is_admin())\n {\n $printme .= \"(Set as Primary)\";\n $printme .= \" (Delete)\";\n }\n $printme .= \"
\";\n $aliases++;\n }\n $printme .= \"

\";\n echo $printme;\n\n # Degree\n $printme = \"

\\n\";\n $printme .= \"DEGREE:
\\n\";\n $printme .= \" - \".$thisperson['degree'];\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n $printme .= \"

\";\n echo $printme;\n\n # Discipline\n $printme = \"

\\n\";\n $printme .= \"DISCIPLINE:
\\n\";\n if (isset($thisperson['discipline_id']))\n {\n $discipline = find_discipline($thisperson['discipline_id']);\n $printme .= \" - \".$discipline['title'].\"\";\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n }\n else\n {\n $printme .= \" - None\";\n if (is_admin())\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n }\n $printme .= \"

\";\n echo $printme;\n\n # School\n $printme = \"

\\n\";\n $printme .= \"SCHOOL:
\\n\";\n if (isset($thisperson['completedyear']))\n {\n $printme .= \" - \".$thisperson['school'].\" (\".$thisperson['country'].\") (\".$thisperson['completedyear'].\")\";\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n }\n else\n {\n $printme .= \" - None\";\n if (is_admin())\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n }\n $printme .= \"

\\n\";\n echo $printme;\n\n\n # Advisors\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"ADVISORS: \";\n if (is_admin() && isset($thisperson['completedyear']))\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['advisors'])){\n foreach ($thisperson['advisors'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\";\n echo $printme;\n\n # Committee Members\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"COMMITTEE MEMBERS: \";\n if (is_admin() && isset($thisperson['completedyear']))\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['cmembers'])){\n foreach ($thisperson['cmembers'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\\n\\n\";\n\n # Admin Notes\n if (is_admin())\n {\n if ($thisperson['notes'] != \"\")\n {\n $printme .= \"

\";\n $printme .= \"\\n\";\n $printme .= \"\\n\";\n $printme .= \"
\\n\";\n $printme .= \"Admin Notes: \".$thisperson['notes'].\"
\\n\";\n $printme .= \"
\\n\";\n $printme .= \"

\\n\\n\";\n }\n }\n\n $glossaryterms = find_glossaryterms();\n # Status and Inspection\n $printme .= \"

\";\n $printme .= \"MPACT Status: \".$statuscodes[$thisperson['status']].\"
\\n\";\n $printme .= \"

\\n\\n\";\n\n # Title and Abstract\n $printme .= \"

\";\n $printme .= \"Title: \".$thisperson['title'].\"
\";\n $printme .= \"

\\n\";\n $printme .= \"

\";\n $printme .= \"Abstract: \".$thisperson['abstract_html'].\"
\";\n $printme .= \"

\\n\\n\";\n\n # print it all out...\n echo $printme;\n\n # URLS\n\n if (is_admin())\n {\n $urls = find_urls_by_person($passed_person);\n echo \"

\\n\";\n echo \"REFERENCE URLS\";\n echo \" (Add)\";\n echo \"
\\n\";\n if (count($urls) > 0)\n {\n echo \"\\n\";\n }\n else\n {\n echo \" - None\\n\";\n }\n foreach ($urls as $one)\n {\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n }\n if (count($urls) > 0)\n {\n echo \"
Updated: \".$one['updated_at'].\"\";\n echo \" (Edit)\";\n echo \" (Delete)\";\n echo \"
\".$one['url'].\"
\".$one['description'].\"
\\n\";\n }\n echo \"

\\n\";\n }\n\n # EDIT HISTORY\n \n if (is_admin())\n {\n $entries = get_dissertation_history($thisperson['dissertation_id']);\n if (count($entries) > 0)\n {\n echo \"

\\n\";\n echo \"EDIT HISTORY (Show/Hide)\\n\";\n echo \"\";\n echo \"\\n\";\n }\n\n foreach ($entries as $one)\n {\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n if (count($entries) > 0)\n {\n echo \"
\".$one['logged_at'].\"\".$one['user'].\"\".$one['message'].\"
\\n\";\n echo \"

\\n\";\n }\n }\n\n\n\n echo \"
\\n\";\n\n # MPACT Scores\n $printme = \"\";\n $printme .= \"

MPACT Scores for $fullname

\";\n $printme .= \"

\";\n $mpact = mpact_scores($passed_person);\n $printme .= $mpact['output'];\n $printme .= \"

\\n\";\n if (is_admin())\n {\n $printme .= \"

(Recalculate)

\";\n }\n echo $printme;\n\n # Draw FamilyTree Graph for this person\n echo \"

Advisors and Advisees Graph

\\n\";\n echo \"

\";\n draw_tree_dotgraph($passed_person);\n echo \"

\";\n\n echo \"
\\n\";\n\n\n # Students\n echo \"

Students under $fullname

\\n\\n\";\n\n # Advisees\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"ADVISEES: \";\n if (is_admin())\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['advisorships'])){\n foreach ($thisperson['advisorships'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n $schoolinfo = find_persons_school($one);\n if (isset($schoolinfo['completedyear']))\n {\n $printme .= \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\\n\";\n echo $printme;\n\n # Committeeships\n $ccount = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"COMMITTEESHIPS: \";\n if (is_admin())\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['committeeships'])){\n foreach ($thisperson['committeeships'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n $schoolinfo = find_persons_school($one);\n if (isset($schoolinfo['completedyear']))\n {\n $printme .= \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\";\n echo $printme;\n\n }\n \n }\n\n\n}\n\n\n?>\n"}, "files_after": {"mpact.php": " \"N/A\",\n \"-1\" => \"N/A\",\n \"0\" => \"Incomplete - Not_Inspected\",\n \"1\" => \"Incomplete - Inspected\",\n \"2\" => \"Incomplete - Ambiguous\",\n \"3\" => \"Complete - Except Indecipherables\",\n \"4\" => \"Fully Complete\"\n);\n\n$inspectioncodes = array(\n NULL => \"N/A\",\n \"0\" => \"No\",\n \"1\" => \"Yes\"\n);\n\n$degree_types = array(\n \"Unknown\",\n \"Unknown - Investigated\",\n \"A.L.A.\",\n \"B.A.\",\n \"B.S.\",\n \"B.L.S.\",\n \"L.L.B.\",\n \"H.A.\",\n \"M.A.\",\n \"M.S.\",\n \"M.F.A.\",\n \"M.P.A.\",\n \"D.E.A.\",\n \"Ed.M.\",\n \"F.L.A. (by thesis)\",\n \"LL.M.\",\n \"LL.D.\",\n \"M.L.S.\",\n \"D.S.N.\",\n \"D.S.W.\",\n \"D.Engr.\",\n \"D.Lib.\",\n \"Ed.D.\",\n \"Th.D.\",\n \"Pharm.D.\",\n \"D.Sc.\",\n \"D.L.S.\",\n \"J.D.\",\n \"M.D.\",\n \"Ph.D.\"\n);\n\n// Begin Session\nsession_start();\n\n// Delete server session if client cookie doesn't exist\nif (!isset($_COOKIE['MPACT_userid'])){\n unset($_SESSION['MPACT']);\n}\n\n// Check for good cookie (and expired session) - (re)set session values accordingly\nif (isset($_COOKIE['MPACT_userid']) && !isset($_SESSION['MPACT'])){\n $query = \"SELECT id, username, fullname FROM users WHERE id='\".$_COOKIE['MPACT_userid'].\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n $line = mysqli_fetch_array($result);\n $_SESSION['MPACT']['userid'] = $line['id'];\n $_SESSION['MPACT']['username'] = $line['username'];\n $_SESSION['MPACT']['fullname'] = $line['fullname'];\n}\n\n###############################################\n// DISPLAY SOMETHING - something from the URL\nif ($_SERVER['REQUEST_METHOD'] == 'GET')\n{\n // Display header\n xhtml_web_header();\n\n// echo \"-----\\n\";\n// print_r($_COOKIE);\n// echo \"-----\\n\";\n// print_r($_SESSION);\n// echo \"-----\\n\";\n if (isset($_GET['op']))\n {\n switch ($_GET['op'])\n {\n ###############################################\n case \"login\";\n\n $host_info = get_environment_info();\n if ($host_info['hostname'] == \"sils\"){\n # no logins here - go to dev server\n action_box(\"No Logins Here...\",2,$_SERVER['SCRIPT_NAME']);\n }\n else{\n if (!isset($_SESSION['MPACT']['userid'])){\n # login form\n echo \"

Welcome

\\n\";\n echo \"

Please login if you have an account.

\\n\";\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"

Username:

Password:

     
\\n\";\n echo \"
\";\n }\n else{\n # um, already logged in...\n action_box(\"Already Logged In...\",2,$_SERVER['SCRIPT_NAME']);\n }\n }\n\n break;\n ###############################################\n case \"logout\";\n\n setcookie('MPACT_userid',$_SESSION['MPACT']['userid'],time()-1000);\n unset($_SESSION['MPACT']);\n action_box(\"Logged Out\",2,$_SERVER['SCRIPT_NAME']);\n\n break;\n ###############################################\n case \"glossary\";\n\n if ( isset($_GET['id']) ){\n show_glossaryterm($_GET['id']);\n }\n else\n {\n show_glossary();\n }\n\n break;\n ###############################################\n case \"admin\";\n\n if (is_admin())\n {\n echo \"

Administrator Pages

\\n\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"Show Logs\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"Show Orphans\\n\";\n echo \"
\\n\";\n echo \"Citation Correlation\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"People with Multiple Dissertations (Errors in DB)\\n\";\n echo \"
\\n\";\n echo \"Year 0000\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"Add a New Person to the Database\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"No Title/Abstract\\n\";\n echo \"
\\n\";\n echo \"LIS, No Title/Abstract\\n\";\n echo \"
\\n\";\n echo \"LIS, No Title\\n\";\n echo \"
\\n\";\n echo \"LIS, No Abstract\\n\";\n echo \"
\\n\";\n echo \"
\\n\";\n echo \"LIS, No Committee\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"

\\n\";\n echo \"LIS, Graduates By Year\\n\";\n echo \"
\\n\";\n echo \"LIS History\\n\";\n echo \"

\\n\";\n\n echo \"

\\n\";\n echo \"LIS Professors Summary\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with MPACT\\n\";\n echo \"
\\n\";\n echo \"LIS Professors and their Degrees (large CSV)\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with Unknown Degree\\n\";\n echo \"
\\n\";\n echo \"LIS Professors with Unknown-Investigated Degree\\n\";\n echo \"
\\n\";\n echo \"LIS Professors without Dissertations\\n\";\n echo \"
\\n\";\n echo \"LIS Professors without LIS Dissertations\\n\";\n echo \"

\\n\";\n\n echo \"
\\n\";\n\n echo \"
\";\n\n show_alphabet();\n\n }\n else\n {\n not_admin();\n }\n\n break;\n ###############################################\n case \"glossary_edit\";\n\n if ( isset($_GET['id']) && is_admin() ){\n\n echo \"

Edit a Glossary Definition

\\n\";\n\n $query = \"SELECT id, term, definition FROM glossary WHERE id='\".$_GET['id'].\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $results['term'] = $line['term'];\n $results['definition'] = $line['definition'];\n }\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\".$results['term'].\":
\\n\";\n echo \"\\n\";\n echo \"
\\n\";\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n\n\n }\n else\n {\n not_admin();\n }\n\n break;\n ###############################################\n case \"show_tree\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n draw_tree((int)$_GET['id']);\n }\n\n break;\n\n ###############################################\n case \"show_graph\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n echo \"

\\n\";\n echo \"Advisors and Advisees of \".get_person_link($_GET['id']);\n echo \"

\\n\";\n draw_graph((int)$_GET['id']);\n }\n\n break;\n\n ###############################################\n case \"statistics\":\n\n echo \"

\\n\";\n echo \"LIS Incomplete - \\n\";\n echo \"Top A -\\n\";\n echo \"Top C -\\n\";\n echo \"Top A+C -\\n\";\n echo \"Top T -\\n\";\n echo \"Top G -\\n\";\n echo \"Top W -\\n\";\n echo \"Top TD -\\n\";\n echo \"Top TA\\n\";\n echo \"

\\n\";\n\n echo \"

Overall MPACT Statistics

\\n\";\n\n echo \"\\n\";\n\n # disciplines\n $query = \"SELECT count(*) as disciplinecount FROM disciplines\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # schools\n $query = \"SELECT count(*) as schoolcount FROM schools\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # diss\n $query = \"SELECT count(*) as disscount FROM dissertations\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # a\n $query = \"SELECT count(*) as advisorcount FROM advisorships\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # c\n $query = \"SELECT count(*) as committeeshipscount FROM committeeships\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n\n # full\n $query = \"SELECT count(*) as peoplecount FROM people\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n echo \"
Disciplines\".$disciplinecount.\"
Schools\".$schoolcount.\"
Dissertations\".$disscount.\"
Advisorships\".$advisorcount.\"
Committeeships\".$committeeshipscount.\"
People\".$peoplecount.\"
\\n\";\n\n\n # dissertations by country\n echo \"

\\n\";\n echo \"

Dissertations by Country:


\\n\";\n $query = \"SELECT count(*) as dissnone FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"\\\")\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as dissusa FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"USA\\\")\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as disscanada FROM dissertations WHERE school_id IN (SELECT id FROM schools WHERE country = \\\"Canada\\\")\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n $query = \"SELECT count(*) as dissother FROM dissertations WHERE school_id IN\n (SELECT id FROM schools WHERE (country != \\\"\\\" AND country != \\\"USA\\\" AND country != \\\"Canada\\\"))\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n echo \"\\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"\n \n \\n\";\n echo \"
USA\".$dissusa.\"\".sprintf(\"%.2f\",100*$dissusa/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa)/$disscount).\"%
Canada\".$disscanada.\"\".sprintf(\"%.2f\",100*$disscanada/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada)/$disscount).\"%
Other\".$dissother.\"\".sprintf(\"%.2f\",100*$dissother/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada+$dissother)/$disscount).\"%
None Listed\".$dissnone.\"\".sprintf(\"%.2f\",100*$dissnone/$disscount).\"%\".sprintf(\"%.2f\",100*($dissusa+$disscanada+$dissother+$dissnone)/$disscount).\"%
Total\".$disscount.\"\".sprintf(\"%.2f\",100*$disscount/$disscount).\"%
\\n\";\n\n # dissertations by year\n echo \"

\\n\";\n echo \"

Dissertations by Year:


\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations GROUP BY completedyear\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n ksort($counts);\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n\n break;\n\n\n ###############################################\n case \"show_logs\":\n\n if (is_admin())\n {\n echo \"

Recent Activity

\\n\";\n\n if (isset($_GET['offset']))\n {\n $entries = get_logs($_GET['offset']);\n }\n else\n {\n $entries = get_logs();\n }\n echo \"\\n\";\n foreach ($entries as $entry)\n {\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
\".$entry['logged_at'].\"
\".$entry['ip'].\"
\".$entry['user'].\"\".$entry['message'].\"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_multi_dissertations\":\n\n if (is_admin())\n {\n echo \"

People With Multiple Dissertations (db needs to be edited by hand)

\\n\";\n\n $query = \"SELECT\n count(d.id) as howmany,\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n GROUP BY\n d.person_id\n ORDER BY\n howmany DESC\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $multicount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n if ($d['howmany'] > 1)\n {\n print \"person id = \".$d['person_id'];\n print \"
\";\n print \"
\";\n $multicount++;\n }\n }\n if ($multicount == 0)\n {\n print \" - None - database is clear.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_zero_year\":\n\n if (is_admin())\n {\n echo \"

Dissertations from the year 0000

\\n\";\n\n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.discipline_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.completedyear = '0000'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n # get school\n $query = \"SELECT fullname\n FROM\n schools\n WHERE id = '\".$d['school_id'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $schoolname = $line['fullname'];\n }\n # get degree\n $query = \"SELECT degree\n FROM\n people\n WHERE id = '\".$d['person_id'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $degree = $line['degree'];\n }\n $discipline = find_discipline($d['discipline_id']);\n echo \"\";\n echo \"\";\n echo \"\";\n print \"\";\n print \"\";\n print \"\";\n print \"\";\n }\n if ($zerocount == 0)\n {\n print \"\";\n }\n echo \"
$zerocount.\".get_person_link($d['person_id']).\"$degree\".$discipline['title'].\"$schoolname
None - database is clear.
\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Title

\\n\";\n\n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.title = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have titles.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_abstract_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Abstract

\\n\";\n\n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.abstract = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_abstract\":\n\n if (is_admin())\n {\n echo \"

Dissertations Without Title/Abstract

\\n\";\n\n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.title = '' OR d.abstract = ''\n ORDER BY\n d.school_id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All dissertations have titles and abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"find_no_title_abstract_lis\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations Without Title/Abstract

\\n\";\n\n $query = \"SELECT\n d.id, d.person_id, d.school_id, d.completedyear\n FROM\n dissertations d\n WHERE\n d.discipline_id = 1 AND\n ( d.title = '' OR d.abstract = '' )\n ORDER BY\n d.school_id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertations = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertations[] = $line;\n }\n $zerocount = 0;\n echo \"

\\n\";\n foreach ($dissertations as $d)\n {\n $zerocount++;\n print \"$zerocount. \";\n echo get_person_link($d['person_id']);\n $thisperson = find_persons_school($d['person_id']);\n print \" - \".$thisperson['school'];\n print \" (\".$d['completedyear'].\")\";\n print \"
\";\n }\n if ($zerocount == 0)\n {\n print \" - None - All LIS dissertations have titles and abstracts.\";\n }\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_unknown_degree\":\n\n if (is_admin())\n {\n echo \"

LIS Professors with Unknown Degree

\\n\";\n\n # advisors or committee members with unknown degree,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n $lis_with_unknown = array();\n\n # get advisors for each diss, check for advisor's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $advisors = array();\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n foreach($advisors as $aid){\n $adv = find_person($aid);\n if ($adv['degree'] == \"Unknown\"){\n $lis_with_unknown[] = $aid;\n }\n }\n }\n\n # get committeeships for each diss, check for comm's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $committeemembers = array();\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n foreach($committeemembers as $cid){\n $com = find_person($cid);\n if ($com['degree'] == \"Unknown\"){\n $lis_with_unknown[] = $cid;\n }\n }\n }\n\n # uniquify\n $lis_with_unknown = array_unique($lis_with_unknown);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($lis_with_unknown as $pid){\n $count++;\n $person = find_person($pid);\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_unknowninvestigated\":\n case \"lis_profs_unknowninvestigated_degree\":\n\n# if (is_admin())\n# {\n echo \"

LIS Professors with Unknown-Investigated Degree

\\n\";\n\n # advisors or committee members with unknown-investigated degree,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n $lis_with_unknown = array();\n\n # get advisors for each diss, check for advisor's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $advisors = array();\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n foreach($advisors as $aid){\n $adv = find_person($aid);\n if ($adv['degree'] == \"Unknown - Investigated\"){\n $lis_with_unknown[] = $aid;\n }\n }\n }\n\n # get committeeships for each diss, check for comm's degree\n # if unknown degree, save\n foreach ($lis_dissertations as $id){\n $committeemembers = array();\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n foreach($committeemembers as $cid){\n $com = find_person($cid);\n if ($com['degree'] == \"Unknown - Investigated\"){\n $lis_with_unknown[] = $cid;\n }\n }\n }\n\n # uniquify\n $lis_with_unknown = array_unique($lis_with_unknown);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($lis_with_unknown as $pid){\n $count++;\n $person = find_person($pid);\n print \"$count. \";\n print get_person_link($pid);\n $advisorcount = count(find_advisorships_under_person($pid));\n $commcount = count(find_committeeships_under_person($pid));\n $totalcommitteeships = $advisorcount + $commcount;\n if ($totalcommitteeships > 1){print \"\";}\n print \" : $advisorcount + $commcount = $totalcommitteeships\";\n if ($totalcommitteeships > 1){print \"\";}\n print \"
\\n\";\n $allcommitteeships += $totalcommitteeships;\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n\n print \"
TOTAL COMMITTEESHIPS = $allcommitteeships
\";\n\n echo \"

\\n\";\n\n# }\n# else\n# {\n# not_admin();\n# }\n\n break;\n\n\n ###############################################\n case \"lis_profswithoutdiss\":\n\n if (is_admin())\n {\n echo \"

LIS Professors without Dissertations

\\n\";\n\n # advisors or committee members with no dissertation,\n # that served on an lis dissertation\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n $total = array_merge($advisors,$committeemembers);\n $unique = array_unique($total);\n\n $unique_list = implode(\",\",$unique);\n $listed = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $listed[] = $line['person_id'];\n }\n $notlisted = array_diff($unique,$listed);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($notlisted as $pid){\n $count++;\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_degrees\":\n\n if (is_admin())\n {\n echo \"

LIS Professors and their Degrees

\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n print \"

Copy and Paste the text below into a .csv file.

\";\n\n # big loop\n print \"
\\n\";\n          print \"
\";\n print \"Count,DissID,DissYear,DissLastName,DissFirstName,DissSchool,DissCountry,AdvisorID,AdvisorType,AdvisorLastName,AdvisorFirstName,\";\n print \"AdvisorDegree,AdvisorYear,AdvisorDiscipline,AdvisorSchool,AdvisorCountry\\n\";\n $count = 0;\n foreach($lis_dissertations as $did){\n # loop through advisors\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $did\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n\n # advisor line\n\n # Count\n $count++;\n print \"\\\"$count\\\",\";\n # DissID\n print \"\\\"$did\\\",\";\n # DissYear\n $diss = find_dissertation($did);\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # DissLastName\n $author = find_person($diss['person_id']);\n print \"\\\"\".$author['lastname'].\"\\\",\";\n # DissFirstName\n print \"\\\"\".$author['firstname'].\"\\\",\";\n # DissSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # DissCountry\n print \"\\\"\".$school['country'].\"\\\",\";\n # AdvisorID\n $pid = $line['person_id'];\n print \"\\\"$pid\\\",\";\n # AdvisorType\n print \"\\\"Advisor\\\",\";\n # AdvisorLastName\n $person = find_person($pid);\n print \"\\\"\".$person['lastname'].\"\\\",\";\n # AdvisorFirstName\n print \"\\\"\".$person['firstname'].\"\\\",\";\n # AdvisorDegree\n print \"\\\"\".$person['degree'].\"\\\",\";\n $diss = find_dissertation_by_person($pid);\n if ($diss){\n # AdvisorYear\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # AdvisorDiscipline\n $disc = find_discipline($diss['discipline_id']);\n print \"\\\"\".$disc['title'].\"\\\",\";\n # AdvisorSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # AdvisorCountry\n print \"\\\"\".$school['country'].\"\\\"\";\n }\n else{\n # no dissertation for this person\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\"\";\n }\n print \"\\n\";\n\n }\n # loop through committeeships\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $did\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n\n # committeeship line\n\n # Count\n $count++;\n print \"\\\"$count\\\",\";\n # DissID\n print \"\\\"$did\\\",\";\n # DissYear\n $diss = find_dissertation($did);\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # DissLastName\n $author = find_person($diss['person_id']);\n print \"\\\"\".$author['lastname'].\"\\\",\";\n # DissFirstName\n print \"\\\"\".$author['firstname'].\"\\\",\";\n # DissSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # DissCountry\n print \"\\\"\".$school['country'].\"\\\",\";\n # AdvisorID\n $pid = $line['person_id'];\n print \"\\\"$pid\\\",\";\n # AdvisorType\n print \"\\\"Committee\\\",\";\n # AdvisorLastName\n $person = find_person($pid);\n print \"\\\"\".$person['lastname'].\"\\\",\";\n # AdvisorFirstName\n print \"\\\"\".$person['firstname'].\"\\\",\";\n # AdvisorDegree\n print \"\\\"\".$person['degree'].\"\\\",\";\n $diss = find_dissertation_by_person($pid);\n if ($diss){\n # AdvisorYear\n print \"\\\"\".$diss['completedyear'].\"\\\",\";\n # AdvisorDiscipline\n $disc = find_discipline($diss['discipline_id']);\n print \"\\\"\".$disc['title'].\"\\\",\";\n # AdvisorSchool\n $school = find_school($diss['school_id']);\n print \"\\\"\".$school['fullname'].\"\\\",\";\n # AdvisorCountry\n print \"\\\"\".$school['country'].\"\\\"\";\n }\n else{\n # no dissertation for this person\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\",\";\n print \"\\\"\\\"\";\n }\n print \"\\n\";\n\n }\n }\n echo \"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profsnotfromlis\":\n\n if (is_admin())\n {\n\n echo \"

LIS Professors without LIS Dissertations

\\n\";\n\n # and then once the data collection is done\n # cassidy wants a list of all the people who were advisors and committee\n # members for lis, but were not themselves lis\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n $total = array_merge($advisors,$committeemembers);\n $unique = array_unique($total);\n\n $unique_list = implode(\",\",$unique);\n $listed = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $listed[] = $line['person_id'];\n }\n $notlisted = array_diff($unique,$listed);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($notlisted as $pid){\n $count++;\n print \"$count. \";\n print get_person_link($pid);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_nocommittee\":\n\n if (is_admin())\n {\n\n echo \"

LIS Dissertations with no committee

\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT count(*) as howmany\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n if ($line['howmany'] > 0){$hascomm[] = $id;};\n }\n }\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT count(*) as howmany\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n if ($line['howmany'] > 0){$hascomm[] = $id;};\n }\n }\n $unique = array_unique($hascomm);\n $nocomm = array_diff($lis_dissertations,$unique);\n\n # print them out\n echo \"

\\n\";\n $count = 0;\n foreach($nocomm as $did){\n $count++;\n print \"$count. \";\n $d = find_dissertation($did);\n print get_person_link($d['person_id']);\n print \"
\\n\";\n }\n if ($count == 0)\n {\n print \" - None\";\n }\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_profs_with_mpact\":\n\n if (is_admin())\n {\n echo \"

LIS Professors With MPACT

\\n\";\n\n # advisors or committee members\n # that served on an lis dissertation\n\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n\n $total = array_merge($advisors,$committeemembers);\n\n $unique = array_unique($total);\n\n echo \"
\\n\";\n          echo \"Count|Name|Year|A|C|A+C|T\\n\";\n          foreach ($unique as $prof){\n            $mpact = mpact_scores($prof);\n            $person = find_person($prof);\n            $dissertation = find_dissertation_by_person($prof);\n            # count\n            $count += 1;\n            echo \"$count\";\n            echo \"|\";\n            # name\n            echo $person['fullname'];\n            echo \"|\";\n            # year\n            echo $dissertation['completedyear'];\n            echo \"|\";\n            # a\n            echo $mpact['A'];\n            echo \"|\";\n            # c\n            echo $mpact['C'];\n            echo \"|\";\n            # a+c\n            echo $mpact['AC'];\n            echo \"|\";\n            # t\n            echo $mpact['T'];\n            echo \"\\n\";\n          }\n          echo \"
\\n\";\n }\n\n break;\n\n ###############################################\n case \"lis_profs_summary\":\n\n if (is_admin())\n {\n echo \"

LIS Professors Summary

\\n\";\n\n # advisors or committee members\n # that served on an lis dissertation\n\n echo \"\\n\";\n\n # get list of LIS dissertations\n $query = \"SELECT\n d.id\n FROM\n dissertations d\n WHERE\n d.discipline_id = '1'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $lis_dissertations[] = $line['id'];\n }\n echo \"\\n\";\n\n # get advisors for each diss\n $advisors = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM advisorships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[] = $line['person_id'];\n }\n }\n echo \"\\n\";\n\n # get committeeships for each diss\n $committeemembers = array();\n foreach ($lis_dissertations as $id){\n $query = \"SELECT person_id\n FROM committeeships\n WHERE dissertation_id = $id\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[] = $line['person_id'];\n }\n }\n echo \"\\n\";\n\n $total = array_merge($advisors,$committeemembers);\n echo \"\\n\";\n\n $unique = array_unique($total);\n echo \"\\n\";\n\n $unique_list = implode(\",\",$unique);\n $known = array();\n $query = \"SELECT person_id\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $known[] = $line['person_id'];\n }\n echo \"\\n\";\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n discipline_id != 16\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n completedyear != 0000\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n $query = \"SELECT count(*) as howmany\n FROM dissertations\n WHERE\n person_id IN ($unique_list)\n AND\n completedyear != 107\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $howmany = $line['howmany'];\n }\n echo \"\\n\";\n\n echo \"
Total LIS Dissertations\".count($lis_dissertations).\"
Total LIS Dissertation Advisorships\";\n echo count($advisors);\n echo \"
Total LIS Dissertation Committeeships\";\n echo count($committeemembers);\n echo \"
Total LIS Dissertation Advisorships and Committeeships:\";\n echo count($total);\n echo \"
Total number of unique advisor/committee members on LIS dissertations:\";\n\n echo count($unique);\n echo \"
\";\n echo \"Subset of \".count($unique).\" without a listed dissertation:\";\n echo count(array_diff($unique,$known));\n echo \"
Subset of \".count($unique).\" with a listed dissertation:\";\n echo count($known);\n echo \"
- Subset of \".count($known).\" with known discipline:\";\n echo $howmany;\n echo \"
- Subset of \".count($known).\" with known year:\";\n echo $howmany;\n echo \"
- Subset of \".count($known).\" with known school:\";\n echo $howmany;\n echo \"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_allyears\":\n\n if (is_admin())\n {\n echo \"

LIS, Graduates By Year

\\n\";\n print \"
\\n\";\n\n            # get list of dissertations\n            $query = \"SELECT\n                      d.id, d.person_id, d.completedyear\n                    FROM\n                      dissertations d\n                    WHERE\n                      d.discipline_id = '1'\n                    ORDER BY\n                      d.completedyear ASC,\n                      d.school_id ASC\n                    \";\n            $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n            $schools = array();\n            $count = 0;\n            while ( $line = mysqli_fetch_array($result)) {\n              $dissertation = find_dissertation($line['id']);\n              $person = find_person($line['person_id']);\n              $schoolinfo = find_persons_school($line['person_id']);\n              $count++;\n              print $count;\n              print \"|\";\n              print $line['completedyear'];\n              print \"|\";\n              print $schoolinfo['school'];\n              print \"|\";\n              print $person['fullname'];\n#              print \"|\";\n#              print $dissertation['title'];\n#              print \"|\";\n#              print $dissertation['abstract'];\n              print \"\\n\";\n            }\n\n            print \"
\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_history\":\n\n if (is_admin())\n {\n echo \"

LIS Dissertations by School by Year

\\n\";\n\n $firstyear = 1920;\n $lastyear = 2008;\n\n print \"
\\n\";\n            print \"school|\";\n            for ($i = $firstyear; $i <= $lastyear; $i++)\n            {\n                print \"$i|\";\n            }\n            print \"\\n\";\n\n            # get list of schools (all of them)\n            $query = \"SELECT\n                    s.id, s.fullname\n                    FROM\n                      schools s\n                    ORDER BY\n                      s.fullname\n                    \";\n            $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n            $schools = array();\n            while ( $line = mysqli_fetch_array($result)) {\n              $schools[] = $line;\n            }\n            foreach ($schools as $s)\n            {\n              # loop through each school and find count by year\n              $query = \"SELECT\n                    d.id, d.person_id, d.completedyear, COUNT(d.completedyear) AS yeartotal\n                    FROM\n                      dissertations d\n                    WHERE\n                      d.discipline_id = '1' AND\n                      d.school_id = '\".$s['id'].\"'\n                    GROUP BY\n                      d.completedyear\n                  \";\n              $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n              print $s['fullname'].\"|\";\n              $d = array();\n              while ( $line = mysqli_fetch_array($result)) {\n                $d[$s['id']][$line['completedyear']] = $line['yeartotal'];\n              }\n\n              # walk through all years, and print out counts for this school\n              for ($i = $firstyear; $i <= $lastyear; $i++)\n              {\n                if ($d[$s['id']][$i] > 0)\n                  print $d[$s['id']][$i].\"|\";\n                else\n                  print \"0|\";\n              }\n              print \"\\n\";\n            }\n\n            print \"
\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"lis_incomplete\":\n\n echo \"

Incomplete LIS Dissertation Listings

\\n\";\n\n $discipline_id = 1; # hard coded for LIS\n $schools = find_schools($discipline_id);\n\n foreach ($schools as $one => $two)\n {\n\n $year_conferred = array();\n $degree_status = array();\n\n $query = \"SELECT d.person_id, d.completedyear, d.status\n FROM\n dissertations d,\n schools s,\n people p,\n names n\n WHERE\n s.id = '$one' AND\n d.discipline_id = '$discipline_id' AND\n d.school_id = s.id AND\n d.person_id = p.id AND\n p.preferred_name_id = n.id AND\n d.status < 4\n ORDER BY\n s.id ASC, d.completedyear ASC, n.lastname ASC, n.firstname ASC\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n $resultcount = 0;\n\n while ( $line = mysqli_fetch_array($result)) {\n $resultcount++;\n extract($line);\n $year_conferred[$person_id] = $completedyear;\n $degree_status[$person_id] = $status;\n }\n\n if ($resultcount > 0)\n {\n echo \"

$two

\\n\";\n }\n\n $incompletecount = 0;\n echo \"\";\n foreach ($year_conferred as $person => $year)\n {\n $incompletecount++;\n $printme = \"\\n\";\n $printme .= \"\\n\";\n\n $printme .= \"\\n\";\n $printme .= \"\\n\";\n\n echo $printme;\n }\n echo \"
$incompletecount. \";\n $printme .= \"\".get_person_link($person).\" ($year)\".$statuscodes[$degree_status[$person]].\"
\";\n\n }\n echo \"

\";\n\n break;\n\n ###############################################\n case \"all_edges\":\n\n if (is_admin())\n {\n echo \"

All Dissertations and Mentor Relationships

\\n\";\n\n print \"
\\n\";\n            print \"mentor|role|protege|year|school\\n\";\n\n            # each dissertation\n            $query = \"SELECT id, person_id, completedyear, school_id FROM dissertations\";\n            $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n            while ( $line = mysqli_fetch_array($result)) {\n              extract($line);\n              $student = find_person($person_id);\n              $query2 = \"SELECT fullname as schoolname FROM schools WHERE id = '$school_id'\";\n              $result2 = mysql_query($query2) or die(mysql_error());\n              $line2 = mysqli_fetch_array($result2);\n              extract($line2);\n              print $student['fullname'].\"|dissertation|null|$completedyear|$schoolname\\n\";\n              # get advisorships\n              $advisors = find_advisors_for_person($person_id);\n              foreach ($advisors as $mentor_id){\n                $mentor = find_person($mentor_id);\n                print $mentor['fullname'].\"|advisorship|\".$student['fullname'].\"|$completedyear|$schoolname\\n\";\n              }\n              # get committeeships\n              $committee = find_committee_for_person($person_id);\n              foreach ($committee as $mentor_id){\n                $mentor = find_person($mentor_id);\n                print $mentor['fullname'].\"|committeeship|\".$student['fullname'].\"|$completedyear|$schoolname\\n\";\n              }\n            }\n            print \"
\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"citation_correlation\":\n\n if (is_admin())\n {\n echo \"

Citation Correlation Data

\\n\";\n\n $correlated_ids = array(\n 953,\n 2098,\n# 5086, bc\n 3659,\n# 1329, dalhousie\n 5087,\n 478,\n 3094,\n 3497,\n 4784,\n 1250,\n 5088,\n 5089,\n 5090,\n 4657,\n# 5091, mcdowell, not phd yet\n 5092,\n 5093,\n 5094,\n 2668,\n 4076,\n 2683,\n 3978,\n 2425,\n 3645,\n 2660,\n 2233,\n 2665,\n 1310,\n 2548,\n 2708,\n 2592,\n 4648,\n 5095,\n 5096,\n 4654,\n 5097,\n 5098,\n 1234,\n 1299,\n 1294,\n 3062,\n 3110,\n 1283,\n 1220,\n 874,\n 584,\n 3127,\n 1142,\n 3116,\n 5099,\n 5100,\n 1025,\n 486,\n 3130,\n 1321,\n 5101,\n 4502,\n 5102,\n 535,\n 5160, # koohang\n 2673,\n 5103,\n 5104,\n 1950,\n 3972,\n 3278,\n 5105,\n 3571,\n 5106,\n 3994,\n 1504,\n 4181,\n 3140,\n 2323, # benoit added\n 5107,\n 800,\n 4438,\n 5108,\n 5109,\n 4760,\n 2570,\n 1866,\n 3238,\n 1846,\n 1806,\n 2527,\n 3703,\n 4758,\n 3683,\n 3846,\n 2603,\n 4011,\n 2343,\n 2329,\n 5110,\n 5111,\n 4706,\n 2761,\n 1413,\n 3028,\n 3590,\n 3668,\n 2883,\n 3063,\n 3091,\n 1705,\n 3031,\n# gary again 486,\n 3979,\n 3018,\n 1855,\n 3409,\n 2747,\n 3093,\n 3065,\n 3060,\n 1685,\n 2114,\n 5112,\n# moore rm 5113,\n 2309,\n# liu rm 2215,\n 4086,\n 4013,\n 1573\n );\n\n echo \"\\n\";\n echo \"\n \n \n \n \n \n \n \n \n \n \\n\";\n $counter = 0;\n foreach ($correlated_ids as $one)\n {\n $counter++;\n echo \"\";\n echo \"\";\n echo \"\";\n $scores = mpact_scores($one);\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
-NameACA+CFMIFMEFMI/(A+C)FME/(A+C)
$counter.\";\n echo get_person_link($one);\n echo \"\".$scores['A'].\"\".$scores['C'].\"\".$scores['AC'].\"\".$scores['FMI'].\"\".$scores['FME'].\"\".$scores['FMIdivFULL'].\"\".$scores['FMEdivFULL'].\"
\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"top_a\":\n case \"top_c\":\n case \"top_ac\":\n case \"top_g\":\n case \"top_td\":\n case \"top_w\":\n case \"top_t\":\n case \"top_ta\":\n\n $list_type = strtoupper(substr($_GET['op'],4));\n echo \"

Top \";\n if ($list_type == \"TD\"){echo \"TD\";}\n else if ($list_type == \"TA\"){echo \"TA\";}\n else if ($list_type == \"AC\"){echo \"A+C\";}\n else {echo $list_type;}\n echo \" List

\\n\";\n $score_type = strtolower($list_type).\"_score\";\n $people = find_all_people();\n foreach ($people as $p)\n {\n $scores[$p] = find_mpact_score($p,$score_type);\n }\n # zero out indecipherables\n $scores[28] = 0;\n $scores[391] = 0;\n asort($scores);\n $scores = array_reverse($scores, true);\n $top = narray_slice($scores, 0, 100); #calls custom function, end of mpact_include (passes true)\n $count = 0;\n $lasttotal = 0;\n echo \"\\n\";\n foreach ($top as $one => $two)\n {\n $count++;\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n $lasttotal = $two;\n }\n echo \"
\";\n if ($two != $lasttotal){echo $count.\".\";}\n echo \"\";\n echo get_person_link($one);\n echo \"\";\n echo $two;\n echo \"
\\n\";\n break;\n\n ###############################################\n case \"create_discipline\":\n\n if (is_admin())\n {\n echo \"

Creating a New Discipline

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
Title
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_discipline\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n elseif (!is_empty_discipline($_GET['id']))\n {\n action_box(\"Discipline must be empty to edit...\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else{\n\n $query = \"SELECT title FROM disciplines WHERE id=\".$_GET['id'];\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

Editing a Discipline

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
Title
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_school\":\n\n if (is_admin())\n {\n echo \"

Creating a New School

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FullnameCountry
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n elseif (!is_empty_school($_GET['id']))\n {\n action_box(\"School must be empty to edit...\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else{\n\n $query = \"SELECT fullname, country FROM schools WHERE id=\".$_GET['id'];\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

Editing a School

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FullnameCountry
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_person\":\n\n if (is_admin())\n {\n echo \"

Creating a New Person

\\n\";\n\n echo \"

\";\n\n echo \"

\\n\";\n echo \"\\n\";\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffixDegree
\";\n echo \"\\n\";\n echo \"
\";\n\n echo \"\";\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_mentor\":\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n\n echo \"

Adding a Mentor

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Mentor Type:
\\n\";\n echo \" Advisor
\\n\";\n echo \" Committee Member\\n\";\n echo \"

\\n\";\n\n echo \"Mentor:
\\n\";\n echo \"\\n\";\n\n echo \"

\\n\";\n\n echo \"Student:
\\n\". get_person_link($_GET['id']);\n echo \"

\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_student\":\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n\n echo \"

Adding a Student

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Mentor Type:
\\n\";\n echo \" Advisor
\\n\";\n echo \" Committee Member\\n\";\n echo \"

\\n\";\n\n echo \"Mentor:
\\n\". get_person_link($_GET['id']);\n echo \"

\\n\";\n\n\n echo \"Student:
\\n\";\n echo \"\\n\";\n\n echo \"

\\n\";\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n\n ###############################################\n case \"remove_mentor\":\n\n if (is_admin())\n {\n echo \"

Removing a Mentor

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Are you sure you want to remove this mentor relationship?

\\n\";\n if ($_GET['type'] == \"A\"){echo \"Advisor: \";}\n if ($_GET['type'] == \"C\"){echo \"Commitee Member: \";}\n echo get_person_link(intval($_GET['mentor_id'])).\"
\\n\";\n echo \"Student: \".get_person_link(intval($_GET['student_id'])).\"
\\n\";\n echo \"
\\n\";\n\n echo \"\";\n echo \" If NOT, please go BACK\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree(intval($_GET['student_id']));\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_url\";\n\n if (is_admin())\n {\n echo \"

Adding a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:
Description:
\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree(intval($_GET['id']));\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_url\";\n\n if (is_admin())\n {\n $url = find_url(intval($_GET['id']));\n echo \"

Editing a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:
Description:
Last Updated:\".$url['updated_at'].\"
\\n\";\n\n echo \"\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($url['person_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_url\";\n\n if (is_admin())\n {\n $url = find_url(intval($_GET['id']));\n echo \"

Deleting a Reference URL

\\n\";\n\n echo \"
\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n\n echo \"Are you sure you want to delete this Reference URL?

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"
URL:\".$url['url'].\"
Description:\".$url['description'].\"
Last Updated:\".$url['updated_at'].\"
\\n\";\n echo \"
\\n\";\n\n echo \"\";\n echo \" If NOT, please go BACK\";\n\n echo \"

\";\n echo \"
\";\n\n draw_tree($url['person_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_degree\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Editing a Degree

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
NameDegree
\".$person['fullname'].\"\";\n echo \"\\n\";\n echo \"
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Adding an Alias

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffix
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['id']);\n\n echo \"

Editing a Name

\";\n echo \"

\";\n\n echo \"

\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n\n\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"
FirstMiddleLastSuffix
\";\n\n echo \"\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n echo \"
\";\n draw_tree($_GET['id']);\n echo \"
\";\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_dissertation\":\n\n if (is_admin())\n {\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n\n if (!$_GET['person_id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_person($_GET['person_id']);\n if (!$person)\n {\n action_box(\"Person not found.\");\n }\n else{\n\n echo \"

CREATE DISSERTATION

\\n\";\n\n echo \"
\";\n echo \"\";\n echo \"\";\n\n echo \"

\";\n echo get_person_link($person['id']);\n echo \"
\";\n\n echo \"Degree: \\n\";\n echo \"
\";\n\n echo \"Status: \\n\";\n echo \"
\";\n\n echo \"Discipline: \\n\";\n echo \"
\";\n\n\n echo \"School: \";\n echo \"\\n\";\n echo \"
Year:\\n\";\n echo \"
\";\n echo \"Title:

\";\n echo \"Abstract:

\";\n echo \"\";\n echo \"

\";\n\n echo \"
\";\n\n echo \"

\";\n echo \"Currently:\";\n echo \"

\";\n echo \"
\";\n draw_tree($person['id']);\n echo \"
\";\n }\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"edit_dissertation\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n $dissertation = find_dissertation(intval($_GET['id']));\n if (!$dissertation)\n {\n action_box(\"Dissertation not found.\");\n }\n else{\n\n $person = find_person($dissertation['person_id']);\n\n echo \"

EDIT DISSERTATION DETAILS

\\n\";\n\n echo \"
\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n echo \"

\";\n echo get_person_link($person['id']);\n echo \"
\";\n\n echo \"Degree: \\n\";\n echo \"
\";\n\n echo \"Status: \\n\";\n echo \"
\";\n\n echo \"Discipline: \\n\";\n echo \"
\";\n\n echo \"School: \\n\";\n\n echo \"
Year:\\n\";\n echo \"
\";\n echo \"Title:

\";\n echo \"Abstract:

\";\n echo \"Admin Notes:

\";\n echo \"\";\n echo \"

\";\n\n echo \"
\";\n\n echo \"

\";\n echo \"Currently:\";\n echo \"

\";\n echo \"
\";\n draw_tree($person['id']);\n echo \"
\";\n }\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_name\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $person = find_name($_GET['name']);\n\n echo \"

\";\n\n echo \"Are you sure you want to delete this name?\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\";\n\n echo \"

\";\n echo \"[ \".$person['firstname'].\" \".$person['middlename'].\" \".$person['lastname'].\" \".$person['suffix'].\" ]
\";\n echo \"

\";\n\n\n echo \"

\";\n echo \"\";\n echo \"   Cancel

\";\n\n echo \"
\";\n\n echo \"

\";\n\n\n\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"set_preferred_name\":\n\n if (is_admin())\n {\n\n set_preferred_name($_GET['id'],$_GET['name']);\n\n action_box(\"Preferred Name Selected\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"recalculate_mpact\":\n\n if (is_admin()){\n\n # recalculate MPACT scores for passed person id\n calculate_scores($_GET['id']);\n\n action_box(\"MPACT Scores Recalculated\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_GET['id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"show_orphans\":\n\n if (is_admin())\n {\n\n $orphans = find_orphans();\n\n echo \"

Orphans

\\n\";\n\n echo \"

\\n\";\n $counter = 0;\n foreach ($orphans as $orphan)\n {\n $counter++;\n echo $counter.\" \";\n echo get_person_link($orphan['person_id']);\n echo \" (Delete from Database)\";\n echo \"
\\n\";\n }\n if ($counter < 1){echo \" - No orphans at this time.\";}\n echo \"

\\n\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_person\":\n\n if (is_admin())\n {\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n if (is_orphan($_GET['id']))\n {\n echo \"

\";\n\n echo \"Are you sure you want to delete this person?\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n echo \"

\";\n echo get_person_link($_GET['id']);\n echo \"

\";\n\n\n echo \"

\";\n echo \"

\\n\";\n echo \"\";\n echo \"   Cancel

\";\n\n echo \"
\";\n\n echo \"

\";\n }\n else\n {\n action_box(\"This person cannot be deleted.\");\n }\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"show_disciplines\":\n\n $statustotals = array(0,0,0,0,0);\n $disciplines = find_disciplines();\n $disciplinecounts = find_discipline_counts();\n\n if (is_admin()){\n echo \"

Add a New Discipline to the Database

\\n\";\n }\n\n echo \"

Disciplines Represented Across All Schools

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($disciplines as $one => $two)\n {\n echo \"\";\n echo \"\";\n $statuscounts = find_discipline_statuses($one);\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n if (!isset($disciplinecounts[$one]) || $disciplinecounts[$one]==0)\n {\n $fraction = 0;\n }\n else\n {\n $fraction = 100*$statuscounts[$three]/intval($disciplinecounts[$one]);\n }\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($disciplinecounts);\n echo \"\";\n }\n echo \"\";\n echo \"
Discipline$statuscodes[$one]
$two (\".intval($disciplinecounts[$one]).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($disciplines).\" Disciplines (\".array_sum($disciplinecounts).\" dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"show_discipline\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $discipline_id = intval($_GET['id']);\n\n # Show Discipline Name\n $query = \"SELECT d.title as disciplinename\n FROM disciplines d\n WHERE\n d.id = '$discipline_id'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

$disciplinename

\";\n\n # Show Histograph\n $counts = array();\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations WHERE discipline_id='$discipline_id' GROUP BY completedyear\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n if (count($counts)>0)\n {\n $bigyear = max($counts);\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*intval(200/$bigyear);\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n }\n echo \"

\\n\";\n }\n\n $schools = find_schools($discipline_id);\n $dissertation_count = 0;\n $statustotals = array(0,0,0,0,0);\n echo \"

Schools Represented

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($schools as $one => $two)\n {\n $statuscounts = find_dept_statuses($one,$discipline_id);\n $dissertation_count += array_sum($statuscounts);\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n $fraction = 100*$statuscounts[$three]/array_sum($statuscounts);\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n\n if (array_sum($statustotals)==0)\n {\n $fraction = 0;\n }\n else\n {\n $fraction = 100*$statustotals[$three]/array_sum($statustotals);\n }\n echo \"\";\n }\n echo \"\";\n echo \"
School$statuscodes[$one]
$two (\".array_sum($statuscounts).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($schools).\" Schools ($dissertation_count dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n # link to edit the discipline name\n if (is_empty_discipline($_GET['id']))\n {\n echo \"

\";\n echo \"

Edit Discipline Name

\\n\";\n }\n\n break;\n\n ###############################################\n case \"show_school\":\n\n if (!$_GET['id']){action_box(\"No ID given.\");}\n else\n {\n\n $school_id = intval($_GET['id']);\n\n # Show School Name\n $query = \"SELECT s.fullname as schoolname, s.country\n FROM schools s\n WHERE\n s.id = '$school_id'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n echo \"

$schoolname ($country)

\";\n\n # Show Histograph\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount FROM dissertations WHERE school_id='$school_id' GROUP BY completedyear\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n $bigyear = max($counts);\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*intval(200/$bigyear);\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n\n $disciplines = find_disciplines($school_id);\n $dissertation_count = 0;\n $statustotals = array(0,0,0,0,0);\n echo \"

Disciplines Represented

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($disciplines as $one => $two)\n {\n $statuscounts = find_dept_statuses($school_id,$one);\n $dissertation_count += array_sum($statuscounts);\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n $fraction = 100*$statuscounts[$three]/array_sum($statuscounts);\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($statustotals);\n echo \"\";\n }\n echo \"\";\n echo \"
Discipline$statuscodes[$one]
$two (\".array_sum($statuscounts).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($disciplines).\" Disciplines ($dissertation_count dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n }\n\n # link to edit the school info\n if (is_empty_school($_GET['id']))\n {\n echo \"

\";\n echo \"

Edit School Information

\\n\";\n }\n\n break;\n\n ###############################################\n case \"show_schools\":\n\n $statustotals = array(0,0,0,0,0);\n $schools = find_schools();\n $schoolcounts = find_school_counts();\n\n if (is_admin()){\n echo \"

Add a New School to the Database

\\n\";\n }\n echo \"

Schools Represented Across All Disciplines

\\n\";\n\n echo \"

\\n\";\n echo \"\\n\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $one)\n {\n echo \"\";\n }\n echo \"\";\n foreach ($schools as $one => $two)\n {\n echo \"\";\n echo \"\";\n $statuscounts = find_school_statuses($one);\n foreach (range(0,4) as $three)\n {\n $statustotals[$three] += $statuscounts[$three];\n if (intval($schoolcounts[$one]) == 0){\n $fraction = 0;\n }\n else{\n $fraction = 100*$statuscounts[$three]/intval($schoolcounts[$one]);\n }\n echo \"\";\n }\n echo \"\\n\";\n }\n # summary line\n echo \"\";\n echo \"\";\n echo \"\";\n foreach (range(0,4) as $three)\n {\n $fraction = 100*$statustotals[$three]/array_sum($schoolcounts);\n echo \"\";\n }\n echo \"\";\n echo \"
School$statuscodes[$one]
$two (\".intval($schoolcounts[$one]).\")\".$statuscounts[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
------------------
\";\n echo count($schools).\" Schools (\".array_sum($schoolcounts).\" dissertations)\";\n echo \"\".$statustotals[$three];\n if ($fraction != 0)\n {\n echo \" (\".sprintf(\"%.1f\",$fraction).\"%)\";\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"show_department\":\n\n if (!$_GET['d'] || !$_GET['s']){action_box(\"No ID given.\");}\n else\n {\n\n $school_id = $_GET['s'];\n $discipline_id = $_GET['d'];\n\n\n # Show Discipline Name\n $query = \"SELECT d.title as disciplinename\n FROM disciplines d\n WHERE\n d.id = '$discipline_id'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n # Show School Name\n $query = \"SELECT s.fullname as schoolname, s.country\n FROM schools s\n WHERE\n s.id = '$school_id'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n echo \"\n

\n $disciplinename\n @\n $schoolname ($country)\n

\n \";\n\n # Advisor and Committee Activity\n echo \"

Dissertation Activity and MPACT Scores (click table headings to sort)

\";\n\n echo \"

\";\n $theprofs = find_profs_at_dept($school_id,$discipline_id);\n if (count($theprofs)>0)\n {\n $sortedprofs = array();\n $proflist = \"\";\n $query = \"SELECT id FROM people WHERE id IN (\";\n foreach ($theprofs as $prof){$proflist .= \"$prof,\";}\n $proflist = rtrim($proflist, \",\");\n $query .= \"$proflist) ORDER BY ac_score DESC\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $sortedprofs[] = $line['id'];\n }\n $profcount = 0;\n echo \"\\n\";\n echo \"\n \n \n \n \n \n \n \n \n \n \n \\n\";\n foreach ($sortedprofs as $one)\n {\n echo \"\";\n $profcount++;\n echo \"\";\n echo \"\";\n $scores = mpact_scores($one);\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n echo \"
-NameACA+CGTTATDW
$profcount.\";\n echo get_person_link($one);\n echo \"\".$scores['A'].\"\".$scores['C'].\"\".$scores['AC'].\"\".$scores['G'].\"\".$scores['T'].\"\".$scores['TA'].\"\".$scores['TD'].\"\".$scores['W'].\"
\\n\";\n echo \"

\";\n }\n else\n {\n echo \"

- None Listed

\\n\";\n }\n echo \"
\";\n\n\n\n\n # Dissertations Conferred\n echo \"

Dissertations Conferred

\";\n\n\n\n\n # Show Histograph\n echo \"

\\n\";\n echo \"Dissertations by Year:
\\n\";\n $query = \"SELECT completedyear, count(*) as disscount\n FROM dissertations\n WHERE\n school_id='$school_id' AND\n discipline_id=$discipline_id\n GROUP BY\n completedyear\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $counts[$line['completedyear']] = $line['disscount'];\n }\n echo \"\\n\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n $height=$two*10;\n echo \"\\n\";\n }\n echo \"\";\n echo \"\\n\";\n foreach ($counts as $one => $two)\n {\n echo \"\\n\";\n }\n echo \"\";\n echo \"
\";\n if ($one%10==0)\n {\n echo $one;\n }\n echo \"
\\n\";\n echo \"

\\n\";\n\n\n\n\n\n $query = \"SELECT d.person_id, d.completedyear, d.status\n FROM\n dissertations d,\n schools s,\n people p,\n names n\n WHERE\n s.id = '$school_id' AND\n d.discipline_id = '$discipline_id' AND\n d.school_id = s.id AND\n d.person_id = p.id AND\n p.preferred_name_id = n.id\n ORDER BY\n d.completedyear ASC, n.lastname ASC, n.firstname ASC\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n $year_conferred[$person_id] = $completedyear;\n $degree_status[$person_id] = $status;\n }\n\n $schoolcount = 0;\n echo \"

\";\n foreach ($year_conferred as $person => $year)\n {\n $schoolcount++;\n echo \"
$schoolcount. \";\n echo get_person_link($person);\n echo \" ($year)\";\n if ($degree_status[$person] < 4)\n {\n echo \" ---------------------------------- \".$statuscodes[$degree_status[$person]];\n }\n }\n echo \"

\";\n\n }\n\n break;\n\n ###############################################\n default:\n // oops - not supposed to be here\n action_box(\"invalid action\",1);\n }\n }\n else\n {\n\n if (isset($_GET['show']))\n {\n if ($_GET['show'] == \"all\")\n {\n $alphabet_limiter = \"\"; // set it to show everything\n }\n else\n {\n $alphabet_limiter = $_GET['show'];\n }\n\n show_alphabet();\n\n if (is_admin())\n {\n echo \"

Add a New Person to the Database

\\n\";\n }\n\n if (is_admin()){\n echo \"
\";\n echo \"\";\n echo \"\";\n echo \"\";\n }\n\n // GET ALL DISSERTATIONS IN A HASH\n $disciplines = find_disciplines();\n $query = \"SELECT id, person_id, discipline_id FROM dissertations\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $graduates[$line['person_id']] = $line['discipline_id'];\n }\n\n // LOOP THROUGH ALL PEOPLE FOR THIS LETTER\n echo \"\\n\";\n echo \"\\n\";\n if (is_admin()){echo \"\\n\";}\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n\n $query = \"SELECT n.id, n.firstname,\n n.middlename, n.lastname, n.suffix,\n p.id as person_id\n FROM names n, people p\n WHERE\n n.id = p.preferred_name_id AND\n n.lastname LIKE '\".$alphabet_limiter.\"%'\n ORDER BY n.lastname ASC, n.firstname ASC\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $rowcount = 0;\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n\n $rowcount++;\n\n echo \"\";\n if (is_admin()){\n echo \"\";\n }\n echo \"\";\n echo \"\";\n $discipline = isset($graduates[$person_id]) ? $disciplines[$graduates[$person_id]] : \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n\n if (is_admin()){\n if ($rowcount % 25 == 0){\n echo \"\";\n }\n }\n\n }\n\n echo \"
MergeCountLast NameFull NameDissertation Discipline
$rowcount.$lastname$firstname $middlename $lastname $suffix$discipline
\\n\";\n\n if (is_admin()){\n echo \"\";\n echo \"
\";\n }\n\n echo \"

\\n\";\n\n show_alphabet();\n\n }\n else\n {\n // DISPLAY THE FRONT PAGE\n\n action_box(\"Front Page...\",0.1,\"./\");\n\n }\n\n }\n\n}\n\n\n\n\n\n\n\n\n\n###############################################\n// SOMETHING WAS SUBMITTED - through a form\nelse\n{\n\n if ($_POST['op'] != \"login\"){\n // Display header\n xhtml_web_header();\n }\n\n switch ($_POST['op'])\n {\n ###############################################\n case \"login\";\n\n $host_info = get_environment_info();\n if ($host_info['hostname'] == \"sils\"){\n # no logins here - go to dev server\n action_box(\"No Logins Here...\",2,$_SERVER['SCRIPT_NAME']);\n }\n else{\n # check credentials / start session\n $query = \"SELECT id, username, fullname FROM users\n WHERE username = '\".addslashes($_POST['username']).\"'\n AND password = '\".addslashes($_POST['password']).\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n $line = mysqli_fetch_array($result);\n if (isset($line['id'])){\n # save cookie info for one week\n setcookie('MPACT_userid',$line['id'],time()+60*60*24*7);\n # redirect\n header(\"Location: \".$_SERVER['SCRIPT_NAME']);\n }\n else{\n // Display header\n xhtml_web_header();\n # incorrect credentials\n action_box(\"Please try again...\",2,$_SERVER['SCRIPT_NAME'].\"?op=login\");\n }\n }\n\n break;\n\n ###############################################\n case \"glossary_edit\";\n if (is_admin())\n {\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $query = \"UPDATE glossary\n SET\n definition = '\".$_POST['definition'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # log it\n mpact_logger(\"updated glossary [\".$_POST['term'].\" (\".$_POST['id'].\")] to (\".$_POST['definition'].\")\");\n\n action_box(\"Definition Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=glossary\");\n }\n else\n {\n not_admin();\n }\n break;\n\n ###############################################\n case \"merge_confirm\":\n\n if (is_admin()){\n\n echo \"
\";\n echo \"\";\n echo \"\";\n\n foreach ($_POST['mergers'] as $one)\n {\n echo \"
\";\n echo \"

[$one]

\";\n echo draw_tree( $one );\n echo \"\";\n echo \"
\";\n }\n\n echo \"\";\n echo \"
\";\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"search\":\n\n $results = people_search($_POST['q']);\n\n if (count($results) > 0)\n {\n echo \"

People Search Results for [\".$_POST['q'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['q'].\"].\";\n if (strlen($_POST['q']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n echo \"

Add a New Person to the Database

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"search_title_abstract\":\n\n $results = title_abstract_search($_POST['qta']);\n\n if (count($results) > 0)\n {\n echo \"

Title/Abstract Search Results for [\".$_POST['qta'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['qta'].\"].\";\n if (strlen($_POST['qta']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n\n break;\n\n ###############################################\n case \"search_notes\":\n\n if (is_admin()){\n\n $results = notes_search($_POST['qn']);\n\n if (count($results) > 0)\n {\n echo \"

Admin Notes Search Results for [\".$_POST['qn'].\"]:

\";\n }\n\n echo \"

\\n\";\n $count = 0;\n foreach ($results as $person_id)\n {\n $count++;\n $schoolinfo = find_persons_school($person_id);\n echo \"$count. \".get_person_link($person_id);\n if ($schoolinfo['completedyear'])\n {\n echo \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n echo \"
\\n\";\n }\n if ($count < 1)\n {\n echo \"

\\n\";\n echo \"There were no results for [\".$_POST['qm'].\"].\";\n if (strlen($_POST['qn']) < 2)\n {\n echo \"

\\n\";\n echo \"Please use at least two characters to search.\";\n }\n else\n {\n if (is_admin()){\n echo \"

\\n\";\n }\n }\n echo \"

\\n\";\n }\n\n echo \"

\\n\";\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"merge_doit\":\n\n if (is_admin()){\n\n # delete the family tree's dotgraphs of each person\n foreach ($_POST['mergers'] as $one)\n {\n delete_associated_dotgraphs($one);\n }\n\n # pop off one of the people_ids\n $into = array_pop($_POST['mergers']);\n\n # merge each remaining person into the one above\n foreach ($_POST['mergers'] as $one)\n {\n merge_two_people($one,$into);\n }\n\n # recalculate MPACT scores for merged person id\n calculate_scores($into);\n\n action_box(\"Merge was Successful\",2,$_SERVER['SCRIPT_NAME'].\"?show=\".$_POST['show']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"create_discipline\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['title'] == \"\")\n {\n action_box(\"Need to have at least a Discipline Title.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_discipline\");\n }\n elseif (is_duplicate_discipline($_POST['title']))\n {\n action_box(\"Discipline (\".$_POST['title'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else\n {\n\n # Create Discipline\n $query = \"INSERT disciplines\n SET\n title = '\".$_POST['title'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # Get the just created discipline_id\n $query = \"SELECT id as new_discipline_id, title FROM disciplines\n WHERE\n title = '\".$_POST['title'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n # log it\n mpact_logger(\"created discipline[\".$new_discipline_id.\"] (\".$title.\")\");\n\n action_box(\"Discipline Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_discipline\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['title'] == \"\")\n {\n action_box(\"Need to have at least a Discipline Title.\",3,$_SERVER['SCRIPT_NAME'].\"?op=edit_discipline&id=\".$_POST['discipline_id'].\"\");\n }\n elseif (is_duplicate_discipline($_POST['title']))\n {\n action_box(\"Discipline (\".$_POST['title'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n }\n else\n {\n\n # Edit Discipline\n $query = \"UPDATE disciplines\n SET\n title = '\".$_POST['title'].\"'\n WHERE\n id = '\".$_POST['discipline_id'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # log it\n mpact_logger(\"edited discipline[\".$_POST['discipline_id'].\"] (\".$_POST['title'].\")\");\n\n action_box(\"Discipline Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_disciplines\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_school\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $_POST = array_map('trim',$_POST);\n\n if ($_POST['fullname'] == \"\" || $_POST['country'] == \"\")\n {\n action_box(\"Need to have at least a School name and Country.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_school\");\n }\n elseif (is_duplicate_school($_POST['fullname']))\n {\n action_box(\"School (\".$_POST['fullname'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else\n {\n\n # Create School\n $query = \"INSERT schools\n SET\n fullname = '\".$_POST['fullname'].\"',\n country = '\".$_POST['country'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # Get the just created school_id\n $query = \"SELECT id as new_school_id, fullname FROM schools\n WHERE\n fullname = '\".$_POST['fullname'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n # log it\n mpact_logger(\"created school[\".$new_school_id.\"] (\".$fullname.\")\");\n\n action_box(\"School Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n\n if (is_admin()){\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['fullname'] == \"\" || $_POST['country'] == \"\")\n {\n action_box(\"Need to have at least a School name and Country.\",3,$_SERVER['SCRIPT_NAME'].\"?op=edit_school&id=\".$_POST['school_id'].\"\");\n }\n elseif (is_duplicate_school($_POST['fullname']))\n {\n action_box(\"School (\".$_POST['fullname'].\") already exists.\",3,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n }\n else\n {\n\n # Edit School\n $query = \"UPDATE schools\n SET\n fullname = '\".$_POST['fullname'].\"',\n country = '\".$_POST['country'].\"'\n WHERE\n id = '\".$_POST['school_id'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # log it\n mpact_logger(\"edited school[\".$_POST['school_id'].\"] (\".$_POST['fullname'].\")\");\n\n action_box(\"School Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_schools\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_person\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if ($_POST['lastname'] == \"\")\n {\n action_box(\"Need to have at least a Last Name.\",3,$_SERVER['SCRIPT_NAME'].\"?op=create_person\");\n }\n else\n {\n # Create Name\n $query = \"INSERT names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # Get the just created name_id\n $query = \"SELECT id as new_name_id FROM names\n WHERE\n firstname = '\".$_POST['firstname'].\"' AND\n middlename = '\".$_POST['middlename'].\"' AND\n lastname = '\".$_POST['lastname'].\"' AND\n suffix = '\".$_POST['suffix'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n # Create Person with new_name_id\n $query = \"INSERT people\n SET\n preferred_name_id = '\".$new_name_id.\"',\n degree = '\".$_POST['degree'].\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # Get the just created person_id\n $query = \"SELECT id as new_person_id FROM people\n WHERE\n preferred_name_id = '\".$new_name_id.\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n # Sync them together with new_person_id\n $query = \"UPDATE names\n SET\n person_id = '\".$new_person_id.\"'\n WHERE\n id = '\".$new_name_id.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $after = find_person($new_person_id);\n\n action_box(\"Person Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$new_person_id);\n\n # log it\n mpact_logger(\"created person[\".$new_person_id.\"] (\".$after['fullname'].\")\");\n\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"remove_mentor\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if (remove_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']))\n {\n action_box(\"Mentor Removed\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['student_id']);\n }\n else\n {\n action_box(\"Nope.\");\n }\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_mentor\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n add_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']);\n\n action_box(\"Mentor Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['student_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_student\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n add_mentor($_POST['mentor_type'],$_POST['student_id'],$_POST['mentor_id']);\n\n action_box(\"Student Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['mentor_id']);\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"add_name\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person($_POST['id']);\n\n $query = \"INSERT names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"',\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # get the just created name_id\n $query = \"SELECT id as new_name_id FROM names\n WHERE\n firstname = '\".$_POST['firstname'].\"' AND\n middlename = '\".$_POST['middlename'].\"' AND\n lastname = '\".$_POST['lastname'].\"' AND\n suffix = '\".$_POST['suffix'].\"'\n ORDER BY id DESC\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n # find that full name from the DB\n $added = find_name($new_name_id);\n\n action_box(\"Name Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n # log it\n mpact_logger(\"added name (\".$added['fullname'].\") for person[\".$_POST['id'].\"] (\".$person['fullname'].\")\");\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_name\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $before = find_name($_POST['name_id']);\n\n $query = \"UPDATE names\n SET\n firstname = '\".$_POST['firstname'].\"',\n middlename = '\".$_POST['middlename'].\"',\n lastname = '\".$_POST['lastname'].\"',\n suffix = '\".$_POST['suffix'].\"'\n WHERE\n id = '\".$_POST['name_id'].\"' AND\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $after = find_name($_POST['name_id']);\n\n # delete dotgraph for this person\n delete_associated_dotgraphs($_POST['id']);\n\n action_box(\"Name Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n # log it\n mpact_logger(\"edited name[\".$_POST['name_id'].\"] for person[\".$_POST['id'].\"] from (\".$before['fullname'].\") to (\".$after['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"add_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person(intval($_POST['person_id']));\n\n $query = \"INSERT urls\n SET\n url = '\".$_POST['url'].\"',\n description = '\".$_POST['description'].\"',\n updated_at = now(),\n person_id = '\".$_POST['person_id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Reference URL Added\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id'].\"#urls\");\n # log it\n mpact_logger(\"added URL[\".substr($_POST['url'], 0, 30).\"] for person[\".$_POST['person_id'].\"] (\".$person['fullname'].\")\");\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $url = find_url(intval($_POST['id']));\n $person = find_person($url['person_id']);\n\n $query = \"UPDATE urls\n SET\n url = '\".$_POST['url'].\"',\n description = '\".$_POST['description'].\"',\n updated_at = now()\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Reference URL Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$url['person_id'].\"#urls\");\n # log it\n mpact_logger(\"edited URL[\".substr($_POST['url'], 0, 30).\"] for person[\".$url['person_id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_url\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $url = find_url(intval($_POST['id']));\n $person = find_person($url['person_id']);\n\n $query = \"DELETE FROM urls\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Reference URL Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$url['person_id'].\"#urls\");\n # log it\n mpact_logger(\"deleted URL[\".substr($url['url'], 0, 30).\"] for person[\".$url['person_id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_degree\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $person = find_person(intval($_POST['id']));\n\n $query = \"UPDATE people\n SET\n degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Degree Edited\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$person['id']);\n # log it\n mpact_logger(\"edited degree[\".$_POST['degree'].\"] for person[\".$person['id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"create_dissertation\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $schools = find_schools();\n\n $person = find_person($_POST['person_id']);\n\n $query = \"INSERT INTO dissertations\n SET\n person_id = '\".$_POST['person_id'].\"',\n discipline_id = '\".$_POST['discipline_id'].\"',\n school_id = '\".$_POST['school_id'].\"',\n completedyear = '\".$_POST['completedyear'].\"',\n status = '\".$_POST['status'].\"',\n title = '\".$_POST['title'].\"',\n abstract = '\".$_POST['abstract'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $query = \"UPDATE people\n SET degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['person_id'].\"'\";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Dissertation Created\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id']);\n # log it\n $dissertation = find_dissertation_by_person($_POST['person_id']);\n mpact_logger(\"create dissertation[\".$dissertation['id'].\"] (\".$person['fullname'].\") with school[\".$dissertation['school_id'].\"] (\".$schools[$dissertation['school_id']].\") in year(\".$dissertation['completedyear'].\") with status (\".$statuscodes[$_POST['status']].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"edit_dissertation\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $disciplines = find_disciplines();\n $schools = find_schools();\n\n $dissertation = find_dissertation($_POST['id']);\n $person = find_person($dissertation['person_id']);\n\n $query = \"UPDATE dissertations\n SET\n school_id = '\".$_POST['school_id'].\"',\n discipline_id = '\".$_POST['discipline_id'].\"',\n completedyear = '\".$_POST['completedyear'].\"',\n status = '\".$_POST['status'].\"',\n notes = '\".$_POST['notes'].\"',\n title = '\".$_POST['title'].\"',\n abstract = '\".$_POST['abstract'].\"'\n WHERE\n id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $query = \"UPDATE people\n SET degree = '\".$_POST['degree'].\"'\n WHERE\n id = '\".$_POST['person_id'].\"'\";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Dissertation Saved\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['person_id']);\n # log it\n mpact_logger(\"edit dissertation[\".$_POST['id'].\"] (\".$person['fullname'].\") from school[\".$dissertation['school_id'].\"] (\".$schools[$dissertation['school_id']].\") in year(\".$dissertation['completedyear'].\") to school[\".$_POST['school_id'].\"] (\".$schools[$_POST['school_id']].\") in year(\".$_POST['completedyear'].\")\");\n # look for changes\n # degree\n if ($person['degree'] != $_POST['degree'])\n {\n mpact_logger($dissertation['id'].\" updated degree [\".$_POST['degree'].\"]\",\"dissertation\");\n }\n # discipline\n if ($dissertation['discipline_id'] != $_POST['discipline_id'])\n {\n mpact_logger($dissertation['id'].\" updated discipline [\".$_POST['discipline_id'].\" (\".$disciplines[$_POST['discipline_id']].\")]\",\"dissertation\");\n }\n # school\n if ($dissertation['school_id'] != $_POST['school_id'])\n {\n mpact_logger($dissertation['id'].\" updated school [\".$_POST['school_id'].\" (\".$schools[$_POST['school_id']].\")]\",\"dissertation\");\n }\n # year\n if ($dissertation['completedyear'] != $_POST['completedyear'])\n {\n mpact_logger($dissertation['id'].\" updated completedyear [\".$_POST['completedyear'].\"]\",\"dissertation\");\n }\n # title\n if ($dissertation['title'] != $_POST['title'])\n {\n mpact_logger($dissertation['id'].\" updated title [\".$_POST['title'].\"]\",\"dissertation\");\n }\n # abstract\n if ($dissertation['abstract'] != $_POST['abstract'])\n {\n mpact_logger($dissertation['id'].\" updated abstract [\".$_POST['abstract'].\"]\",\"dissertation\");\n }\n # status\n if ($dissertation['status'] != $_POST['status'])\n {\n mpact_logger($dissertation['id'].\" updated status [\".$statuscodes[$_POST['status']].\"]\",\"dissertation\");\n }\n # status\n if ($dissertation['notes'] != $_POST['notes'])\n {\n mpact_logger($dissertation['id'].\" updated notes [\".$_POST['notes'].\"]\",\"dissertation\");\n }\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"delete_person\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n if (delete_person($_POST['id']))\n {\n action_box(\"Person Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n }\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n\n ###############################################\n case \"delete_name\":\n\n if (is_admin()){\n\n if (!get_magic_quotes_gpc()) {$_POST = array_map('addslashes',$_POST);}\n\n $name = find_name($_POST['name_id']);\n $person = find_person($_POST['id']);\n\n $query = \"DELETE FROM names\n WHERE\n id = '\".$_POST['name_id'].\"' AND\n person_id = '\".$_POST['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n action_box(\"Name Deleted\",2,$_SERVER['SCRIPT_NAME'].\"?op=show_tree&id=\".$_POST['id']);\n\n # log it\n mpact_logger(\"deleted name[\".$_POST['name_id'].\"] (\".$name['fullname'].\") from person[\".$person['id'].\"] (\".$person['fullname'].\")\");\n\n }\n else\n {\n not_admin();\n }\n\n break;\n\n ###############################################\n case \"edit_school\":\n\n break;\n\n ###############################################\n default:\n // oops - not supposed to be here\n action_box(\"oops, back to the front page...\",2);\n\n\n }\n\n\n}\n\nxhtml_web_footer();\n\n?>\n", "mpact_include.php": " $val)\n foreach ($aSubtrahends as $aSubtrahend)\n if (array_key_exists($key, $aSubtrahend))\n unset ($ar1[$key]);\n return $ar1;\n}\n\n# -------------------------------------------------------------------------------\nfunction action_box($message,$bounce = \"0\",$location = \"index.php\"){\n\n echo \"\n

\n $message\n

\n

\n \";\n\n if ($bounce != \"0\"){\n echo \"\n \n

\n Forwarding in $bounce seconds (or click here to do the same)\n

\n \";\n }\n\n}\n\n# -------------------------------------------------------------------------------\nfunction xhtml_orig_web_header(){\n\n # make search box happy\n if (!isset($_POST['q'])){$_POST['q'] = \"\";}\n if (!isset($_POST['qta'])){$_POST['qta'] = \"\";}\n if (!isset($_POST['qn'])){$_POST['qn'] = \"\";}\n\n # print out header info\n echo \"\n\n \n \n \n MPACT\n\n \n \n \n\n \n \n\n \n\n \n \n \n\n
\n \n \n \n \n \n
\n
\n MPACT -\n Database -\n \n People Search: \n
-\n
\n \n Title/Abstract Search: \n
\n\";\n if (is_admin()){\n echo \" -
\n \n Admin Notes Search: \n
\";\n }\n echo \"
\n\";\n if (is_admin()){\n echo $_SESSION['MPACT']['fullname'].\" (\".$_SESSION['MPACT']['username'].\") - Logout\";\n }\n else{\n $host_info = get_environment_info();\n if ($host_info['hostname'] != \"sils\"){\n echo \"Login\";\n }\n }\necho \"\n
\n

\n\n \";\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction xhtml_web_header(){\n\n # make search box happy\n if (!isset($_POST['q'])){$_POST['q'] = \"\";}\n if (!isset($_POST['qta'])){$_POST['qta'] = \"\";}\n if (!isset($_POST['qn'])){$_POST['qn'] = \"\";}\n\n # print out header info\n echo \"\n\n \n \n \n MPACT\n \n \n \n \n \n\n\";\n\necho \"

\";\nif (is_admin()){\n echo $_SESSION['MPACT']['fullname'].\" (\".$_SESSION['MPACT']['username'].\") - Logout\";\n}\nelse{\n echo \"Login\";\n}\necho \"

\";\necho \"
\";\n\necho \"\n
\n \n \n\n \n\n \n\n \n\n \n
\n \n \n \n \n Publications  • \n Project Statistics\n
\n
\n Glossary  • \n Schools  • \n Disciplines\n
\n
\n \n People Search: \n
\n    \n
\n \n Title/Abstract Search: \n
\";\nif (is_admin()){\n echo \"

Administrator Pages\";\n echo \"
\n \n Admin Notes Search: \n
\";\n}\necho \"
\n \n
\n
\n\n
\n
\n\n
\n\n \";\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction xhtml_web_footer(){\n echo \"\n\n
\n\n \n \n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction is_email_valid ($address)\n{\n\n\t# http://www.zend.com/codex.php?id=285&single=1\n\n return (preg_match(\n '/^[-!#$%&\\'*+\\\\.\\/0-9=?A-Z^_`{|}~]+'. // the user name\n '@'. // the ubiquitous at-sign\n '([-0-9A-Z]+\\.)+' . // host, sub-, and domain names\n '([0-9A-Z]){2,4}$/i', // top-level domain (TLD)\n trim($address)));\n}\n\n# -------------------------------------------------------------------------------\nfunction find_glossaryterms()\n{\n global $dbh;\n $query = \"SELECT id, term, definition FROM glossary\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n $glossaryterms = array();\n while ( $line = mysqli_fetch_array($result)) {\n $glossaryterms['ids'][$line['term']] = $line['id'];\n $glossaryterms['defs'][$line['id']] = $line['definition'];\n }\n return $glossaryterms;\n}\n\n# -------------------------------------------------------------------------------\nfunction show_glossary()\n{\n global $dbh;\n $query = \"SELECT id, term, definition FROM glossary ORDER BY term ASC\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $results = array();\n while ( $line = mysqli_fetch_array($result)) {\n array_push($results,$line);\n }\n\n echo \"

Glossary

\\n\";\n\n echo \"

\\n\";\n\n foreach ($results as $one)\n {\n echo \"\".$one['term'].\": \";\n echo $one['definition'];\n if (is_admin())\n {\n echo \" EDIT \";\n }\n echo \"

\";\n }\n\n echo \"

\\n\";\n\n}\n\n# -------------------------------------------------------------------------------\nfunction show_glossaryterm($id)\n{\n global $dbh;\n $query = \"SELECT id, term, definition FROM glossary WHERE id = $id\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $results = array();\n while ( $line = mysqli_fetch_array($result)) {\n $glossaryterm = $line;\n }\n\n echo \"

Full Glossary Listing

\";\n\n echo \"

Glossary

\\n\";\n\n echo \"

\\n\";\n\n echo \"\".$glossaryterm['term'].\": \";\n echo $glossaryterm['definition'];\n if (is_admin())\n {\n echo \" EDIT \";\n }\n echo \"

\";\n\n echo \"

\\n\";\n\n}\n\n# -------------------------------------------------------------------------------\nfunction show_alphabet()\n{\n\n $alphabet_letters = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n $alphabet = preg_split('//', $alphabet_letters, -1, PREG_SPLIT_NO_EMPTY);\n\n echo \"
\\n\";\n echo \"

Dissertation Authors and Mentors by Last Name

\";\n echo \"

\";\n foreach ($alphabet as $letter)\n {\n if ($letter != \"A\"){echo \" - \";}\n echo \"$letter\";\n }\n echo \"

\";\n echo \"
\\n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction search_box($q=\"\")\n{\n echo \"
\\n\";\n echo \"\\n\";\n echo \"

People Search: \";\n if ($q)\n {\n echo \"\\n\";\n }\n else\n {\n echo \"\\n\";\n }\n echo \"

\\n\";\n echo \"
\\n\";\n}\n\n# -------------------------------------------------------------------------------\nfunction people_search($q)\n{\n global $dbh;\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = explode(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$pieces[0].\"%' OR\n n.middlename LIKE '%\".$pieces[0].\"%' OR\n n.lastname LIKE '%\".$pieces[0].\"%' OR\n n.suffix LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (n.firstname LIKE '%\".$pieces[1].\"%' OR\n n.middlename LIKE '%\".$pieces[1].\"%' OR\n n.lastname LIKE '%\".$pieces[1].\"%' OR\n n.suffix LIKE '%\".$pieces[1].\"%')\n\n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$pieces[0].\"%' OR\n n.middlename LIKE '%\".$pieces[0].\"%' OR\n n.lastname LIKE '%\".$pieces[0].\"%' OR\n n.suffix LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (n.firstname LIKE '%\".$pieces[1].\"%' OR\n n.middlename LIKE '%\".$pieces[1].\"%' OR\n n.lastname LIKE '%\".$pieces[1].\"%' OR\n n.suffix LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (n.firstname LIKE '%\".$pieces[2].\"%' OR\n n.middlename LIKE '%\".$pieces[2].\"%' OR\n n.lastname LIKE '%\".$pieces[2].\"%' OR\n n.suffix LIKE '%\".$pieces[2].\"%')\n\n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT n.id as name_id, p.id as person_id\n FROM\n names n, people p\n WHERE\n (\n\n (n.firstname LIKE '%\".$q.\"%' OR\n n.middlename LIKE '%\".$q.\"%' OR\n n.lastname LIKE '%\".$q.\"%' OR\n n.suffix LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = p.id\n GROUP BY\n p.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction title_abstract_search($q)\n{\n global $dbh;\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = explode(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$pieces[0].\"%' OR\n d.abstract LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (d.title LIKE '%\".$pieces[1].\"%' OR\n d.abstract LIKE '%\".$pieces[1].\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$pieces[0].\"%' OR\n d.abstract LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (d.title LIKE '%\".$pieces[1].\"%' OR\n d.abstract LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (d.title LIKE '%\".$pieces[2].\"%' OR\n d.abstract LIKE '%\".$pieces[2].\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.title LIKE '%\".$q.\"%' OR\n d.abstract LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction notes_search($q)\n{\n global $dbh;\n $q = trim($q);\n if (!get_magic_quotes_gpc()) {$q = addslashes($q);}\n $results = array();\n if (strlen($q) < 2){\n return $results;\n }\n\n $pieces = explode(\" \",$q);\n# print_r($pieces);\n if (count($pieces) == 2)\n {\n# echo \" --------- two pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (d.notes LIKE '%\".$pieces[1].\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n elseif (count($pieces) == 3)\n {\n# echo \" --------- three pieces\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$pieces[0].\"%')\n\n AND\n\n (d.notes LIKE '%\".$pieces[1].\"%')\n\n AND\n\n (d.notes LIKE '%\".$pieces[2].\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n else\n {\n# echo \" --- regular search - single piece\";\n $query = \"SELECT d.person_id\n FROM\n names n, dissertations d\n WHERE\n (\n\n (d.notes LIKE '%\".$q.\"%')\n\n )\n AND\n n.person_id = d.person_id\n GROUP BY\n d.id\n ORDER BY\n n.lastname, n.suffix, n.firstname, n.middlename\n \";\n }\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n array_push($results,$line['person_id']);\n }\n return $results;\n}\n\n# -------------------------------------------------------------------------------\nfunction encode_linebreaks($bigtext)\n{\n # from http://us3.php.net/str_replace\n $order = array(\"\\r\\n\", \"\\n\", \"\\r\");\n $replace = '
';\n // Processes \\r\\n's first so they aren't converted twice.\n $with_breaks = str_replace($order, $replace, $bigtext);\n return $with_breaks;\n}\n\n# -------------------------------------------------------------------------------\nfunction get_logs($offset=\"0\")\n{\n global $dbh;\n# echo \"[$offset]\";\n $query = \"SELECT * FROM logs ORDER BY id DESC LIMIT 100\";\n if ($offset != \"\"){$query .= \" OFFSET $offset\";}\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n# echo $query;\n $entries = array();\n $counter = 0;\n while ( $line = mysqli_fetch_array($result)) {\n $counter++;\n $entries[$counter] = $line;\n }\n return $entries;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction get_dissertation_history($id)\n{\n global $dbh;\n $query = \"SELECT * FROM logs\n WHERE type='dissertation' AND message LIKE '$id %'\n ORDER BY id DESC\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n# echo $query;\n $entries = array();\n $counter = 0;\n while ( $line = mysqli_fetch_array($result)) {\n $counter++;\n $entries[$counter] = $line;\n }\n return $entries;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction find_all_people()\n{\n global $dbh;\n # return array of all people_ids in database (slow....)\n # all people\n $query = \"SELECT id as person_id FROM people\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $people[] = $line['person_id'];\n }\n return $people;\n}\n\n# -------------------------------------------------------------------------------\nfunction get_person_link($person_id)\n{\n\n $disciplines = find_disciplines();\n $person = find_person($person_id);\n\n $fullname = trim($person['firstname'].\" \".$person['middlename'].\" \".$person['lastname'].\" \".$person['suffix']);\n\n $dissertation = find_dissertation_by_person($person_id);\n $discipline = isset($dissertation['discipline_id']) ? $disciplines[$dissertation['discipline_id']] : \"\";\n\n $link = \"\".$fullname.\"\";\n\n return $link;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_orphans()\n{\n global $dbh;\n\n # finding people with no dissertation and no students\n\n # all people\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n\n WHERE\n p.preferred_name_id = n.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $people[$line['person_id']] = $line;\n# echo \" \".$line['person_id'].\"
\\n\";\n }\n\n echo \"people: \".count($people).\"
\\n\";\n\n # with dissertations only\n $query = \"SELECT\n p.id as person_id\n FROM\n people p, dissertations d\n WHERE\n d.person_id = p.id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $with_dissertations[$line['person_id']] = $line;\n# echo \" \".$line['person_id'].\"
\\n\";\n }\n\n echo \"dissertations: \".count($with_dissertations).\"
\\n\";\n\n # all people - dissertations = teachers only\n $potentialmentors = array_key_diff($people,$with_dissertations);\n\n echo \"potential mentors: \".count($potentialmentors).\"
\\n\";\n\n # orphans = teachers who don't have students\n # get advisorships\n $query = \"SELECT person_id FROM advisorships\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $advisors[$line['person_id']] = $line;\n }\n echo \"advisors: \".count($advisors).\"
\\n\";\n # get committeeships\n $query = \"SELECT person_id FROM committeeships\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n $committeemembers[$line['person_id']] = $line;\n }\n echo \"committeemembers: \".count($committeemembers).\"
\\n\";\n # subtract advisorships from teachers\n $potentialmentors = array_key_diff($potentialmentors,$advisors);\n # subtract committeeships from remaining teachers\n $orphans = array_key_diff($potentialmentors,$committeemembers);\n echo \"orphans: \".count($orphans).\"
\\n\";\n\n return $orphans;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction is_orphan($person_id)\n{\n global $dbh;\n # confirm person exists\n $query = \"SELECT * FROM people WHERE id = '\".$person_id.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n $line = mysqli_fetch_array($result);\n if (!$line['id']){echo \"not a person\";return 0;}\n # confirm no dissertation\n $query = \"SELECT * FROM dissertations WHERE person_id = '\".$person_id.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n echo \"found a dissertation\";\n return 0;\n }\n # confirm not a committeemember\n $query = \"SELECT * FROM committeeships WHERE person_id = '\".$person_id.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n echo \"found a committeeship\";\n return 0;\n }\n # confirm not an advisor\n $query = \"SELECT * FROM advisorships WHERE person_id = '\".$person_id.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n echo \"found an advisorship\";\n return 0;\n }\n return 1;\n}\n# -------------------------------------------------------------------------------\nfunction delete_person($person_id)\n{\n global $dbh;\n if (is_orphan($person_id))\n {\n $before = find_person($person_id);\n # delete all names\n $query = \"DELETE FROM names WHERE person_id = '\".$person_id.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # delete the person\n $query = \"DELETE FROM people WHERE id = '\".$person_id.\"' LIMIT 1\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # log it\n mpact_logger(\"deleted person[\".$person_id.\"] (\".$before['fullname'].\")\");\n return 1;\n }\n else\n {\n action_box(\"Not an orphan - Cannot delete this person.\");\n return 0;\n }\n}\n# -------------------------------------------------------------------------------\nfunction remove_duplicate_names($person_id)\n{\n global $dbh;\n\n $names = array();\n $deleteme = array();\n\n\n $before = find_person($person_id);\n\n // get the preferred_name_id\n $query = \"SELECT preferred_name_id\n FROM people\n WHERE id = '\".$person_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n // get the full preferred_name\n $query = \"SELECT * FROM names\n WHERE\n id = '\".$preferred_name_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $fullname = \"\".$line['firstname'].\" \".$line['middlename'].\" \".$line['lastname'].\" \".$line['suffix'].\"\";\n $names[$fullname] = $line['id'];\n }\n\n // get the rest of the names for this person\n $query = \"SELECT * FROM names\n WHERE\n person_id = '\".$person_id.\"' AND\n id != '\".$preferred_name_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $fullname = \"\".$line['firstname'].\" \".$line['middlename'].\" \".$line['lastname'].\" \".$line['suffix'].\"\";\n if (isset($names[$fullname]))\n {\n $deleteme[] = $line['id'];\n }\n else\n {\n $names[$fullname] = $line['id'];\n }\n }\n\n // delete each deleteme id\n foreach ($deleteme as $one)\n {\n $query = \"DELETE FROM names\n WHERE\n id = '\".$one.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n }\n\n # log it\n mpact_logger(\"removed duplicate names for person[\".$person_id.\"] (\".$before['fullname'].\")\");\n\n}\n\n# -------------------------------------------------------------------------------\nfunction add_mentor($type,$student_id,$mentor_id)\n{\n global $dbh;\n $student = find_person($student_id);\n $mentor = find_person($mentor_id);\n $dissertation = find_dissertation_by_person($student_id);\n\n if ($type == \"A\")\n {\n # find existing advisors for this student\n $advisors = find_advisors_for_person($student_id);\n # if new/different - then add them to the student's dissertation\n if (in_array($mentor_id,$advisors))\n {\n # skip - already listed as advisor\n }\n else\n {\n $query = \"INSERT advisorships\n SET\n dissertation_id = '\".$dissertation['id'].\"',\n person_id = '\".$mentor_id.\"'\n \";\n# echo $query;\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"add advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n # delete existing dotgraphs - they'll need to be regenerated\n # has to happen after we add the advisor link itself\n delete_associated_dotgraphs($student_id);\n }\n }\n elseif ($type == \"C\")\n {\n # find existing committee members for this student\n $committee = find_committee_for_person($student_id);\n # if new/different - then add them to the student's dissertation\n if (in_array($mentor_id,$committee))\n {\n # skip - already on committee\n }\n else\n {\n $query = \"INSERT committeeships\n SET\n dissertation_id = '\".$dissertation['id'].\"',\n person_id = '\".$mentor_id.\"'\n \";\n# echo $query;\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"add committeeship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n }\n }\n else\n {\n # nothing\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction remove_mentor($type,$student_id,$mentor_id)\n{\n global $dbh;\n $dissertation = find_dissertation_by_person($student_id);\n\n $student = find_person($student_id);\n $mentor = find_person($mentor_id);\n\n if ($type == \"A\")\n {\n # find dissertation id\n $dissertation = find_dissertation_by_person($student_id);\n # find existing advisors for this student\n $advisors = find_advisors_for_person($student_id);\n # if found in db, remove them\n if (!in_array($mentor_id,$advisors))\n {\n echo \"not an advisor for this student\";\n return 0;\n }\n else\n {\n # delete existing dotgraphs - they'll need to be regenerated\n # has to happen before we delete the advisor link itself\n delete_associated_dotgraphs($student_id);\n # delete the advisorship\n $query = \"DELETE FROM advisorships\n WHERE\n person_id = '\".$mentor_id.\"' AND\n dissertation_id = '\".$dissertation['id'].\"'\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"remove advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n return 1;\n }\n }\n elseif ($type == \"C\")\n {\n # find dissertation id\n $dissertation = find_dissertation_by_person($student_id);\n # find existing committee members for this student\n $committee = find_committee_for_person($student_id);\n # if found in db, remove them\n if (!in_array($mentor_id,$committee))\n {\n echo \"not on committee for this student\";\n return 0;\n }\n else\n {\n $query = \"DELETE FROM committeeships\n WHERE\n person_id = '\".$mentor_id.\"' AND\n dissertation_id = '\".$dissertation['id'].\"'\n LIMIT 1\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n # recalculate scores for both\n calculate_scores($student_id);\n calculate_scores($mentor_id);\n # log it\n mpact_logger(\"remove advisorship between mentor[\".$mentor_id.\"] (\".$mentor['fullname'].\") to dissertation[\".$dissertation['id'].\"] (\".$student['fullname'].\")\");\n return 1;\n }\n }\n else\n {\n echo \"has to be A or C, dude\";\n return 0;\n }\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_all_people_for_selectbox($with_dissertation=\"0\")\n{\n global $dbh;\n if ($with_dissertation == \"0\")\n {\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n\n WHERE\n p.preferred_name_id = n.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \";\n }\n else\n {\n $query = \"SELECT\n p.id as person_id, n.firstname, n.middlename, n.lastname, n.suffix\n FROM\n people p, names n, dissertations d\n WHERE\n p.preferred_name_id = n.id AND\n d.person_id = p.id\n ORDER BY n.lastname,n.firstname,n.middlename\n \";\n }\n // echo $query;\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $people[$line['person_id']] = $line;\n }\n\n return $people;\n}\n\n# -------------------------------------------------------------------------------\nfunction merge_two_people($from_id, $into_id)\n{\n global $dbh;\n\n $from_person = find_person($from_id);\n $into_person = find_person($into_id);\n\n\n $query = \"UPDATE advisorships\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $query = \"UPDATE dissertations\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $query = \"UPDATE committeeships\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $query = \"UPDATE urls\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n // move each 'from' name to the 'into' person\n\n $query = \"UPDATE names\n SET\n person_id = '\".$into_person['id'].\"'\n WHERE\n person_id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n // remove any new duplicates in the names table\n\n remove_duplicate_names($into_person['id']);\n\n // remove 'from' person from the database\n\n $query = \"DELETE FROM people\n WHERE\n id = '\".$from_person['id'].\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n # log it\n mpact_logger(\"merged two people [\".$from_id.\"] (\".$from_person['fullname'].\") and [\".$into_id.\"] (\".$into_person['fullname'].\")\");\n\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_aliases($person_id)\n{\n global $dbh;\n\n $query = \"SELECT preferred_name_id\n FROM people\n WHERE id = '\".$person_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n $names = array();\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, n.id\n FROM\n names n\n WHERE\n n.person_id = '\".$person_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $names[$line['id']] = $line;\n }\n\n unset($names[$preferred_name_id]);\n\n return $names;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_person($person_id)\n{\n global $dbh;\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, p.degree,\n p.id, p.preferred_name_id\n FROM\n names n, people p\n WHERE\n p.preferred_name_id = n.id AND\n p.id = \".$person_id.\"\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $person = $line;\n $person['fullname'] = $person['firstname'];\n if ($person['middlename'] != \"\"){$person['fullname'] .= \" \".$person['middlename'];}\n if ($person['lastname'] != \"\"){$person['fullname'] .= \" \".$person['lastname'];}\n if ($person['suffix'] != \"\"){$person['fullname'] .= \" \".$person['suffix'];}\n }\n\n return $person;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_url($url_id)\n{\n global $dbh;\n\n $url_id = intval($url_id);\n $query = \"SELECT\n u.id, u.url, u.description, u.updated_at, u.person_id\n FROM\n urls u\n WHERE\n u.id = '\".$url_id.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $url = $line;\n }\n\n return $url;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_urls_by_person($person_id)\n{\n global $dbh;\n\n $person_id = intval($person_id);\n $query = \"SELECT\n u.id, u.url, u.description, u.updated_at, u.person_id\n FROM\n urls u\n WHERE\n u.person_id = '\".$person_id.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $urls = array();\n while ( $line = mysqli_fetch_array($result)) {\n $urls[$line['id']] = $line;\n }\n\n return $urls;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dissertation($dissertation_id)\n{\n global $dbh;\n\n $dissertation_id = intval($dissertation_id);\n $query = \"SELECT\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n WHERE\n d.id = '\".$dissertation_id.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertation = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertation = $line;\n }\n\n return $dissertation;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dissertation_by_person($person_id)\n{\n global $dbh;\n\n $person_id = intval($person_id);\n $query = \"SELECT\n d.id, d.person_id, d.completedyear, d.status,\n d.title, d.abstract, d.notes, d.school_id, d.discipline_id\n FROM\n dissertations d\n WHERE\n d.person_id = '\".$person_id.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $dissertation = array();\n while ( $line = mysqli_fetch_array($result)) {\n $dissertation = $line;\n }\n\n return $dissertation;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_name($name_id)\n{\n global $dbh;\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix\n FROM\n names n\n WHERE\n n.id = \".$name_id.\"\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $name = $line;\n $name['fullname'] = $name['firstname'];\n if ($name['middlename'] != \"\"){$name['fullname'] .= \" \".$name['middlename'];}\n if ($name['lastname'] != \"\"){$name['fullname'] .= \" \".$name['lastname'];}\n if ($name['suffix'] != \"\"){$name['fullname'] .= \" \".$name['suffix'];}\n }\n\n return $name;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline($discipline_id)\n{\n global $dbh;\n $discipline_id = intval($discipline_id);\n $query = \"SELECT\n d.title, d.description\n FROM\n disciplines d\n WHERE\n d.id = \".$discipline_id.\"\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $discipline = $line;\n }\n\n return $discipline;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_ancestors_for_group($groupofpeople)\n{\n $originalgroup = $groupofpeople;\n // find advisors, and if they're new, add them to the list and recurse\n foreach ($originalgroup as $person)\n {\n $advisors = find_advisors_for_person($person);\n foreach ($advisors as $one)\n {\n $groupofpeople[] = $one;\n }\n }\n $groupofpeople = array_unique($groupofpeople);\n if (count(array_diff($groupofpeople,$originalgroup)) > 0)\n {\n return find_ancestors_for_group($groupofpeople);\n }\n else\n {\n return $originalgroup;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_descendents_for_group($groupofpeople)\n{\n $originalgroup = $groupofpeople;\n // find descendents, and if they're new, add them to the list and recurse\n foreach ($originalgroup as $person)\n {\n $advisees = find_advisorships_under_person($person);\n foreach ($advisees as $one)\n {\n $groupofpeople[] = $one;\n }\n }\n $groupofpeople = array_unique($groupofpeople);\n if (count(array_diff($groupofpeople,$originalgroup)) > 0)\n {\n return find_descendents_for_group($groupofpeople);\n }\n else\n {\n return $originalgroup;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction T_score($person)\n{\n # total number of descendants (nodes) in a person's tree\n $group = array($person);\n $total = count(find_descendents_for_group($group)); # including self\n $descendents = $total - 1; # minus self\n return $descendents;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_mpact_score($person,$score_type)\n{\n global $dbh;\n $query = \"SELECT $score_type as score FROM people WHERE id='$person'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n return $score;\n}\n\n# -------------------------------------------------------------------------------\nfunction FMI_score($person)\n{\n $FMI_score = count(find_advisorships_under_person($person));\n# print \"person $person -- fmi $FMI_score
\";\n $committeeships = find_committeeships_under_person($person);\n foreach ($committeeships as $one)\n {\n $numA = count(find_advisors_for_person($one));\n# echo \" - #A [$numA] ----
\";\n $numC = count(find_committee_for_person($one));\n# echo \"#C [$numC] ---- \\n\";\n $FMI_score += 1/($numA + $numC);\n# echo \"
\";\n }\n // echo \"fractional mentorship, inclusive (FMI = A + eachC(1/(#A+#C)) )
\\n\";\n return round($FMI_score,3);\n}\n\n# -------------------------------------------------------------------------------\nfunction FME_score($person)\n{\n $FME_score = count(find_advisorships_under_person($person));\n# print \"person $person -- fme $FME_score
\";\n $committeeships = find_committeeships_under_person($person);\n foreach ($committeeships as $one)\n {\n $numC = count(find_committee_for_person($one));\n# echo \"#C [$numC] ---- \\n\";\n $FME_score += 1/($numC);\n# echo \"
\";\n }\n // echo \"fractional mentorship, inclusive (FMI = A + eachC(1/(#A+#C)) )
\\n\";\n return round($FME_score,3);\n}\n\n# -------------------------------------------------------------------------------\nfunction TA_score($person)\n{\n # total number of descendants who have advised students themselves\n $without_students = array();\n $descendents = find_descendents_for_group(array($person)); # including self\n foreach ($descendents as $d)\n {\n if (count(find_descendents_for_group(array($d))) == 1)\n {\n $without_students[] = $d;\n }\n }\n $descendents_who_advised = array_diff($descendents,$without_students); # including self\n return max(count($descendents_who_advised) - 1,0); # minus self\n}\n\n# -------------------------------------------------------------------------------\nfunction W_score($person)\n{\n # should handle multigenerational advisorships correctly...\n\n # return the max of the widths of each generation of descendents\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n# print \"$gencount <-- gen
\";\n# print count($advisees).\" advisees - \";\n# print_r($advisees);\n# print \"
\";\n# print \"
\";\n# print count($remaining).\" remaining - \";\n# print_r($remaining);\n# print \"
\";\n# print \"
\";\n while (count($remaining) > 0)\n {\n $gencount++;\n# print \"$gencount <-- gen
\";\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n# print count($advisees).\" advisees - \";\n# print_r($advisees);\n# print \"
\";\n# print \"
\";\n# print count($remaining).\" remaining - \";\n# print_r($remaining);\n# print \"
\";\n# print \"
\";\n }\n# print_r($gen_widths);\n return max($gen_widths);\n}\n\n# -------------------------------------------------------------------------------\nfunction TD_score($person)\n{\n # there is currently a bug in this implementation\n # if a student has two advisors, and they, themselves are related by mentorship\n # this algorithm currently counts gen_width based on advisee count only\n # since $td is calculated based on gen_width values, TD will be missing data\n # A is advisor to B and C\n # B is advisor to C\n # A should have a TD score of 2 (full credit for both advisees)\n # upon further reflection, perhaps this is working correctly, by accident\n\n # return the decayed score\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n while (count($remaining) > 0)\n {\n $gencount++;\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n }\n# print_r($gen_widths);\n $td = 0;\n foreach($gen_widths as $one => $two)\n {\n $num = $two;\n $den = (pow(2,($one-1)));\n $f = $num/$den;\n# print \"$num/$den = $f
\";\n $td = $td + $f;\n }\n return $td;\n}\n\n# -------------------------------------------------------------------------------\nfunction G_score($person)\n{\n # there is currently a bug in this implementation\n # if a student has two advisors, and they, themselves are related by mentorship\n # this algorithm currently misses a generation in the calculation of G\n # A is advisor to B and C\n # B is advisor to C\n # A should have a G score of 2, but will only be calculated a 1\n\n\n # return the number of generations of descendents\n $descendents = array_diff(find_descendents_for_group(array($person)),array($person)); # without self # 16\n $gencount = 1;\n $advisees = find_advisorships_under_person($person); #5\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($descendents,$advisees); # 11\n while (count($remaining) > 0)\n {\n $gencount++;\n $advisees = advisees_of_group($advisees);\n $gen_widths[$gencount] = count($advisees);\n $remaining = array_diff($remaining,$advisees);\n }\n if ($gen_widths[1] == 0)\n {\n return 0;\n }\n else\n {\n return count($gen_widths);\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction advisees_of_group($group)\n{\n # W helper function\n $advisees = array();\n foreach ($group as $one)\n {\n $advisees[] = find_advisorships_under_person($one);\n }\n $advisees = flattenArray($advisees);\n# print_r($advisees);\n# print \" <-- advisees of group
\";\n return $advisees;\n}\n\n# -------------------------------------------------------------------------------\nfunction flattenArray($array)\n{\n $flatArray = array();\n foreach( $array as $subElement ) {\n if( is_array($subElement) )\n $flatArray = array_merge($flatArray, flattenArray($subElement));\n else\n $flatArray[] = $subElement;\n }\n return $flatArray;\n}\n\n# -------------------------------------------------------------------------------\nfunction calculate_scores($person_id)\n{\n global $dbh;\n $A_score = count(find_advisorships_under_person($person_id));\n $C_score = count(find_committeeships_under_person($person_id));\n $AC_score = $A_score + $C_score;\n $G_score = G_score($person_id);\n $W_score = W_score($person_id);\n $T_score = T_score($person_id);\n $TA_score = TA_score($person_id);\n $TD_score = TD_score($person_id);\n $FMI_score = FMI_score($person_id);\n $FME_score = FME_score($person_id);\n\n $query = \"UPDATE people\n SET\n a_score = '$A_score',\n c_score = '$C_score',\n ac_score = '$AC_score',\n g_score = '$G_score',\n w_score = '$W_score',\n t_score = '$T_score',\n ta_score = '$TA_score',\n td_score = '$TD_score',\n fmi_score = '$FMI_score',\n fme_score = '$FME_score',\n scores_calculated = now()\n WHERE\n id = \".$person_id.\"\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n}\n\n# -------------------------------------------------------------------------------\nfunction mpact_scores($passed_person)\n{\n global $dbh;\n $glossaryterms = find_glossaryterms();\n\n $query = \"SELECT\n a_score, c_score, ac_score, g_score, w_score,\n t_score, ta_score, td_score, fmi_score, fme_score,\n scores_calculated\n FROM people\n WHERE id = \".$passed_person.\"\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result)) {\n extract($line);\n }\n\n $mpact['A'] = $a_score;\n $mpact['C'] = $c_score;\n $mpact['AC'] = $ac_score;\n $scores_output = \"A = $a_score
\\n\";\n $scores_output .= \"C = $c_score
\\n\";\n $scores_output .= \"A+C = $ac_score
\\n\";\n\n $mpact['FMI'] = $fmi_score;\n $mpact['FME'] = $fme_score;\n $FMIdivFULL = ($ac_score>0) ? $fmi_score / $ac_score : 0;\n $FMIdivFULL = round($FMIdivFULL,3);\n $mpact['FMIdivFULL'] = $FMIdivFULL;\n $FMEdivFULL = ($ac_score>0) ? $fme_score / $ac_score : 0;\n $FMEdivFULL = round($FMEdivFULL,3);\n $mpact['FMEdivFULL'] = $FMEdivFULL;\n if (is_admin())\n {\n $scores_output .= \"FMI = $fmi_score
\\n\";\n $scores_output .= \"FME = $fme_score
\\n\";\n $scores_output .= \"FMI/(A+C) = $FMIdivFULL
\\n\";\n $scores_output .= \"FME/(A+C) = $FMEdivFULL
\\n\";\n }\n\n $mpact['T'] = $t_score;\n $scores_output .= \"T = $t_score
\\n\";\n $mpact['G'] = $g_score;\n $scores_output .= \"G = $g_score
\\n\";\n $mpact['W'] = $w_score;\n $scores_output .= \"W = $w_score
\\n\";\n $mpact['TD'] = $td_score;\n $scores_output .= \"D']].\"\\\">TD = $td_score
\\n\";\n $mpact['TA'] = $ta_score;\n $scores_output .= \"A']].\"\\\">TA = $ta_score
\\n\";\n $scores_output .= \"calculated $scores_calculated
\\n\";\n $mpact['output'] = $scores_output;\n\n return $mpact;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_advisors_for_person($person_id)\n{\n global $dbh;\n\n // get person's own advisor(s)\n\n $listing = array();\n\n\n $query = \"SELECT a.person_id\n FROM\n dissertations d,\n advisorships a\n WHERE\n d.person_id = \".$person_id.\" AND\n a.dissertation_id = d.id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_committee_for_person($person_id)\n{\n global $dbh;\n\n // get person's own committee member(s)\n\n $listing = array();\n\n $query = \"SELECT c.person_id\n FROM\n dissertations d,\n committeeships c\n WHERE\n d.person_id = \".$person_id.\" AND\n c.dissertation_id = d.id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_advisorships_under_person($person_id)\n{\n global $dbh;\n\n // get person's advisorships (below)\n\n $listing = array();\n\n $query = \"SELECT d.person_id\n FROM\n dissertations d,\n advisorships a\n WHERE\n a.person_id = \".$person_id.\" AND\n a.dissertation_id = d.id\n ORDER BY\n d.completedyear ASC\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_committeeships_under_person($person_id)\n{\n global $dbh;\n\n // get person's committeeships (below)\n\n $listing = array();\n\n $query = \"SELECT d.person_id\n FROM\n dissertations d,\n committeeships c\n WHERE\n c.person_id = '\".$person_id.\"' AND\n c.dissertation_id = d.id\n ORDER BY\n d.completedyear\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $listing[] = $line['person_id'];\n }\n\n return $listing;\n}\n\n# -------------------------------------------------------------------------------\nfunction set_preferred_name($person_id,$name_id)\n{\n global $dbh;\n\n # delete current family tree of dotgraphs\n delete_associated_dotgraphs($person_id);\n\n # set it\n\n $listing = array();\n\n $before = find_person($person_id);\n\n $query = \"UPDATE people\n SET\n preferred_name_id = '\".$name_id.\"'\n WHERE\n id = '\".$person_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n $after = find_person($person_id);\n\n # log it\n mpact_logger(\"set preferred name for person[\".$person_id.\"] from name[\".$before['preferred_name_id'].\"] (\".$before['fullname'].\") to name[\".$name_id.\"] (\".$after['fullname'].\")\");\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_profs_at_dept($school_id,$discipline_id)\n{\n global $dbh;\n\n $dissertations = array();\n $listing = array();\n $advisors = array();\n $committeemembers = array();\n\n // get all dissertations at this dept\n\n $query = \"SELECT d.id\n FROM dissertations d, schools s\n WHERE\n d.school_id = s.id AND\n s.id = '\".$school_id.\"' AND\n d.discipline_id = '\".$discipline_id.\"'\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $dissertations[] = $line['id'];\n }\n\n if (count($dissertations)>0)\n {\n // get all advisors for these dissertations\n\n $query = \"SELECT a.person_id\n FROM dissertations d, advisorships a\n WHERE\n a.dissertation_id IN (\";\n $query .= implode(\", \", $dissertations);\n $query .= \") AND\n a.dissertation_id = d.id\";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $advisors[$line['person_id']] = $line['person_id'];\n }\n\n // get all committeemembers for these dissertations\n\n $query = \"SELECT c.person_id\n FROM dissertations d, committeeships c\n WHERE\n c.dissertation_id IN (\";\n $query .= implode(\", \", $dissertations);\n $query .= \") AND\n c.dissertation_id = d.id\";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $committeemembers[$line['person_id']] = $line['person_id'];\n }\n }\n\n // return the combined list (uniquified when combined)\n\n// echo \"\\na - \".count($advisors);\n// echo \"\\nc - \".count($committeemembers);\n $listing = $advisors + $committeemembers;\n// echo \"\\ncombined before - \".count($listing);\n return $listing;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_profs_at_dept($school_id,$discipline_id)\n{\n global $dbh;\n $query = \"SELECT professors\n FROM profs_at_dept\n WHERE\n school_id = '$school_id' AND\n discipline_id = '$discipline_id'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result))\n {\n $listing = unserialize($line['professors']);\n }\n return $listing;\n\n}\n\n# -------------------------------------------------------------------------------\nfunction find_disciplines($school_id=null)\n{\n global $dbh;\n\n $disciplines = array();\n if ($school_id)\n {\n // get all disciplines at this school\n $query = \"SELECT d.id, d.title\n FROM\n disciplines d, schools s, dissertations diss\n WHERE\n diss.school_id = s.id AND\n diss.discipline_id = d.id AND\n s.id = '$school_id'\n ORDER BY\n d.title\n \";\n }\n else\n {\n $query = \"SELECT id, title\n FROM\n disciplines d\n ORDER BY\n title\n \";\n }\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $disciplines[$line['id']] = $line['title'];\n }\n\n if (isset($disciplines))\n {\n return $disciplines;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction is_duplicate_discipline($title)\n{\n global $dbh;\n $disciplinefound = 0;\n\n $query = \"SELECT id FROM disciplines WHERE title = '$title'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $disciplinefound = $line['id'];\n }\n\n if ($disciplinefound > 0){\n return true;\n }\n\n return false;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_empty_discipline($discipline_id)\n{\n global $dbh;\n $query = \"SELECT count(*) as howmany FROM dissertations WHERE discipline_id = $discipline_id\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n extract($line);\n }\n\n if ($howmany > 0){\n return false;\n }\n\n return true;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_duplicate_school($fullname)\n{\n global $dbh;\n $schoolfound = 0;\n\n $query = \"SELECT id FROM schools WHERE fullname = '$fullname'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $schoolfound = $line['id'];\n }\n\n if ($schoolfound > 0){\n return true;\n }\n\n return false;\n}\n\n# -------------------------------------------------------------------------------\nfunction is_empty_school($school_id)\n{\n global $dbh;\n $query = \"SELECT count(*) as howmany FROM dissertations WHERE school_id = $school_id\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n extract($line);\n }\n\n if ($howmany > 0){\n return false;\n }\n\n return true;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline_counts()\n{\n global $dbh;\n\n // get all discipline counts from the database\n\n $disciplinecounts = array();\n\n $query = \"SELECT discipline_id, count(*) as disciplinecount\n FROM dissertations\n GROUP BY discipline_id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $disciplinecounts[$line['discipline_id']] = $line['disciplinecount'];\n }\n\n if (isset($disciplinecounts))\n {\n return $disciplinecounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_discipline_statuses($discipline_id)\n{\n global $dbh;\n\n // get status counts for this discipline\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n\n $query = \"SELECT status, count(*) as disciplinecount\n FROM dissertations\n WHERE discipline_id='$discipline_id'\n GROUP BY status\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disciplinecount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dept_counts($school_id,$discipline_id)\n{\n global $dbh;\n\n // get all department counts from the database\n\n $deptcounts = array();\n\n $query = \"SELECT discipline_id, count(*) as disciplinecount\n FROM dissertations\n GROUP BY discipline_id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $deptcounts[$line['discipline_id']] = $line['disciplinecount'];\n }\n\n if (isset($deptcounts))\n {\n return $deptcounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_dept_statuses($school_id,$discipline_id)\n{\n global $dbh;\n\n // get status counts for this school in this discipline\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n\n $query = \"SELECT status, count(*) as disciplinecount\n FROM dissertations\n WHERE\n discipline_id='$discipline_id' AND\n school_id='$school_id'\n GROUP BY status\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disciplinecount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n# -------------------------------------------------------------------------------\nfunction find_schools($discipline_id=null)\n{\n global $dbh;\n // get all schools in a discipline (or all disciplines)\n $schools = array();\n if ($discipline_id)\n {\n // look up schools at dissertations in this discipline\n $query = \"SELECT s.id, s.fullname\n FROM\n dissertations d, schools s\n WHERE\n d.school_id = s.id AND\n d.discipline_id = '$discipline_id'\n GROUP BY\n d.school_id\n ORDER BY\n s.fullname ASC\n \";\n }\n else\n {\n $query = \"SELECT id, fullname\n FROM\n schools s\n ORDER BY fullname\n \";\n }\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n while ( $line = mysqli_fetch_array($result))\n {\n $schools[$line['id']] = $line['fullname'];\n }\n\n if (isset($schools))\n {\n return $schools;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school_counts()\n{\n global $dbh;\n\n // get all school dissertation counts from the database\n\n $schoolcounts = array();\n\n $query = \"SELECT school_id, count(*) as disscount\n FROM dissertations\n GROUP BY school_id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $schoolcounts[$line['school_id']] = $line['disscount'];\n }\n\n if (isset($schoolcounts))\n {\n return $schoolcounts;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school_statuses($school_id)\n{\n global $dbh;\n\n // get status counts for this school\n\n GLOBAL $statuscodes;\n\n $statuscounts = array();\n\n $query = \"SELECT status, count(*) as disscount\n FROM dissertations\n WHERE school_id='$school_id'\n GROUP BY status\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result))\n {\n $statuscounts[$line['status']] = $line['disscount'];\n }\n\n foreach (range(0,4) as $one)\n {\n if (!isset($statuscounts[$one]))\n {\n $statuscounts[$one] = 0;\n }\n }\n return $statuscounts;\n}\n\n\n# -------------------------------------------------------------------------------\nfunction find_persons_school($passed_person)\n{\n global $dbh;\n\n // get person's degree school\n\n $query = \"SELECT\n d.id as dissertation_id,\n d.completedyear,\n d.title,\n d.abstract,\n s.fullname,\n s.country,\n s.id as schoolid\n FROM\n dissertations d,\n schools s\n WHERE\n d.person_id = \".$passed_person.\" AND\n d.school_id = s.id\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $thisperson['dissertation_id'] = $line['dissertation_id'];\n $thisperson['completedyear'] = $line['completedyear'];\n $thisperson['title'] = $line['title'];\n $thisperson['abstract'] = $line['abstract'];\n $thisperson['country'] = $line['country'];\n $thisperson['school'] = $line['fullname'];\n $thisperson['schoolid'] = $line['schoolid'];\n }\n\n if (isset($thisperson))\n {\n return $thisperson;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction find_school($school_id)\n{\n global $dbh;\n\n // get school\n\n $query = \"SELECT\n s.fullname,\n s.country\n FROM\n schools s\n WHERE\n s.id = \".$school_id.\"\n \";\n\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $school['country'] = $line['country'];\n $school['fullname'] = $line['fullname'];\n }\n\n if (isset($school))\n {\n return $school;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction get_environment_info()\n{\n $host_info = array();\n $hostname = $_SERVER['SERVER_NAME'];\n if ($hostname == \"\"){$hostname = exec(hostname);}\n# echo \"hostname = [$hostname]
\";\n if ($hostname == \"www.ibiblio.org\" || $hostname == \"www-dev.ibiblio.org\" || $hostname == \"login1.ibiblio.org\")\n {\n # the main install on ibiblio\n $host_info['hostname'] = \"ibiblio\";\n $host_info['ownername'] = \"mpact\";\n $host_info['dotlocation'] = \"/export/sunsite/users/mpact/terrelllocal/bin/dot\";\n $host_info['appdir'] = \"/public/html/mpact\";\n $host_info['webdir'] = \"http://www.ibiblio.org/mpact\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"Times-Roman\";\n }\n else if ($hostname == \"trel.dyndns.org\")\n {\n # my local development machine\n $host_info['hostname'] = \"home\";\n $host_info['ownername'] = \"trel\";\n $host_info['dotlocation'] = \"/sw/bin/dot\";\n $host_info['appdir'] = \"/Library/WebServer/Documents/MPACTlocal/app\";\n $host_info['webdir'] = \"http://trel.dyndns.org:9000/mpactlocal/app\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"cour\";\n }\n else if ($hostname == \"localhost.com\" || $hostname == \"trelpancake\")\n {\n # my laptop\n $host_info['hostname'] = \"laptop\";\n $host_info['ownername'] = \"trel\";\n $host_info['dotlocation'] = \"/opt/local/bin/dot\";\n $host_info['appdir'] = \"/Users/trel/Sites/MPACT\";\n $host_info['webdir'] = \"http://localhost.com/~trel/MPACT\";\n $host_info['dotcachedir'] = \"dotgraphs\";\n $host_info['dotfiletype'] = \"png\";\n $host_info['dotfontface'] = \"cour\";\n }\n else\n {\n # unknown host\n #exit;\n }\n\n return $host_info;\n}\n\n# -------------------------------------------------------------------------------\nfunction delete_associated_dotgraphs($passed_person)\n{\n $host_info = get_environment_info();\n $group = array($passed_person);\n $ancestors = find_ancestors_for_group($group);\n $descendents = find_descendents_for_group($group);\n $entire_family_tree = array_unique($ancestors + $descendents);\n foreach ($entire_family_tree as $one)\n {\n # set the filenames\n $dotfilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.dot\";\n $imagefilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.\".$host_info['dotfiletype'];\n $imagemapfilename = $host_info['appdir'].\"/\".$host_info['dotcachedir'].\"/$one.map\";\n # delete each if they exist\n if (file_exists($dotfilename))\n {\n `rm $dotfilename`;\n }\n if (file_exists($imagefilename))\n {\n `rm $imagefilename`;\n }\n if (file_exists($imagemapfilename))\n {\n `rm $imagemapfilename`;\n }\n # mark as 'dirty' so cronjob can recreate images\n mark_record_as_dirty($one);\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction mark_record_as_dirty($passed_person)\n{\n global $dbh;\n # mark database record for this person as dirty\n # a cronjob will pick these up and regenerate their dotgraphs\n # gets around permission issues on the server if necessary\n $query = \"UPDATE people SET regenerate_dotgraph = '1' WHERE id = '\".$passed_person.\"'\";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n}\n\n# -------------------------------------------------------------------------------\nfunction narray_slice($array, $offset, $length) {\n # http://us3.php.net/manual/en/function.array-slice.php#73882\n\n //Check if this version already supports it\n if (str_replace('.', '', PHP_VERSION) >= 502)\n return array_slice($array, $offset, $length, true);\n\n foreach ($array as $key => $value) {\n\n if ($a >= $offset && $a - $offset <= $length)\n $output_array[$key] = $value;\n $a++;\n\n }\n return $output_array;\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_dotfile($passed_person){\n $a = find_person($passed_person);\n if ($a == null)\n {\n return 0;\n }\n else\n {\n $dotfilecontents = \"\";\n $dotfilecontents .= \"digraph familytree\\n\";\n $dotfilecontents .= \"{\\n\";\n $dotfilecontents .= \"rankdir=\\\"LR\\\"\\n\";\n $dotfilecontents .= \"node [fontname = Times, fontsize=10, shape = rect, height=.15]\\n\";\n # ancestors\n $upgroup = array();\n $upgroup[] = $passed_person;\n $ancestors = find_ancestors_for_group($upgroup);\n foreach ($ancestors as $one)\n {\n $person = find_person($one);\n $dotfilecontents .= \"$one [label = \\\"\".$person['fullname'].\"\\\" URL=\\\"mpact.php?op=show_tree&id=\".$one.\"\\\"];\\n\";\n $advisors = find_advisors_for_person($one);\n foreach ($advisors as $adv)\n {\n $dotfilecontents .= \"$adv -> $one;\\n\";\n }\n }\n # descendents\n $downgroup = array();\n $downgroup[] = $passed_person;\n $descendents = find_descendents_for_group($downgroup);\n foreach ($descendents as $one)\n {\n $person = find_person($one);\n $dotfilecontents .= \"$one [label = \\\"\".$person['fullname'].\"\\\" URL=\\\"mpact.php?op=show_tree&id=\".$one.\"\\\"\";\n if ($one == $passed_person){\n $dotfilecontents .= \" color=\\\"red\\\" style=\\\"filled\\\" fillcolor=\\\"grey\\\"\";\n }\n $dotfilecontents .= \"];\\n\";\n $advisees = find_advisorships_under_person($one);\n foreach ($advisees as $adv)\n {\n $dotfilecontents .= \"$one -> $adv;\\n\";\n }\n }\n $dotfilecontents .= \"}\\n\";\n\n return $dotfilecontents;\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_tree_dotgraph($passed_person)\n{\n $person = $passed_person;\n $host_info = get_environment_info();\n if (isset($host_info['appdir']))\n {\n $webfilename = generate_dotgraph($person);\n if ($webfilename == \"marked_as_dirty\"){\n echo \"generating graph, please reload\";\n }\n else{\n echo \"\\\"Directed
\";\n }\n }\n else\n {\n echo \"graphics libraries are not configured\";\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction generate_dotgraph($passed_person, $forcenew=\"no\")\n{\n $person = $passed_person;\n $host_info = get_environment_info();\n# print_r($host_info);\n $appcache = $host_info['appdir'].\"/\".$host_info['dotcachedir'];\n $webcache = $host_info['webdir'].\"/\".$host_info['dotcachedir'];\n $appfilename = \"$appcache/$person.\".$host_info['dotfiletype'];\n# echo \"appfilename = $appfilename
\\n\";\n $dotfilename = \"$appcache/$person.dot\";\n# echo \"dotfilename = $dotfilename
\\n\";\n $webfilename = \"$webcache/$person.\".$host_info['dotfiletype'];\n# echo \"webfilename = $webfilename
\\n\";\n $appimagemap = \"$appcache/$person.map\";\n# echo \"appimagemap = $appimagemap
\\n\";\n\n if (!file_exists($appfilename)) {\n # assumption is that the cachedir exists... (run setupmpact.sh)\n # generate dotfile\n if (!file_exists($dotfilename) or $forcenew == \"force\") {\n# print \" - creating dotfile...\\n\";\n $dotfilecontents = generate_dotfile($person);\n $fh = fopen($dotfilename, 'w');\n fwrite($fh, $dotfilecontents);\n fclose($fh);\n exec(\"chmod 666 $dotfilename\");\n }\n # generate graph\n $getandgenerategraph = \"/bin/cat $dotfilename | \".$host_info['dotlocation'].\" -Nfontname=\".$host_info['dotfontface'].\" -Gcharset=latin1 -Tcmapx -o$appimagemap -T\".$host_info['dotfiletype'].\" -o$appfilename 2>&1\";\n# echo \"getandgenerategraph = $getandgenerategraph
\";\n exec($getandgenerategraph);\n exec(\"chmod 666 $appimagemap\");\n exec(\"chmod 666 $appfilename\");\n if (!file_exists($appfilename)) {\n # mark as dirty if it didn't work\n mark_record_as_dirty($person);\n return \"marked_as_dirty\";\n }\n }\n else\n {\n# echo \"SHOWING CACHED COPY
\";\n }\n\n return $webfilename;\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_graph($passed_person)\n{\n if (!$passed_person){action_box(\"No ID given.\");}\n\n $person = $passed_person;\n $host_info = get_environment_info();\n if (isset($host_info['appdir']))\n {\n $appcache = $host_info['appdir'].\"/\".$host_info['dotcachedir'];\n $webcache = $host_info['webdir'].\"/\".$host_info['dotcachedir'];\n $appfilename = \"$appcache/$person.\".$host_info['dotfiletype'];\n #echo \"appfilename = $appfilename
\";\n $webfilename = \"$webcache/$person.\".$host_info['dotfiletype'];\n #echo \"webfilename = $webfilename
\";\n $appimagemap = \"$appcache/$person.map\";\n #echo \"appimagemap = $appimagemap
\";\n\n\n echo \"\";\n echo file_get_contents($appimagemap);\n }\n else\n {\n echo \"graphics libraries are not configured\";\n }\n}\n\n# -------------------------------------------------------------------------------\nfunction draw_tree($passed_person)\n{\n global $dbh;\n GLOBAL $statuscodes;\n GLOBAL $inspectioncodes;\n\n // shows a person\n\n if (!$passed_person){action_box(\"No ID given.\");}\n else\n {\n $personcount = 0;\n $thisperson = array();\n $dissertation = array();\n\n // get person's preferred name\n\n $query = \"SELECT\n n.firstname, n.middlename,\n n.lastname, n.suffix, p.degree\n FROM\n names n, people p\n WHERE\n p.preferred_name_id = n.id AND\n p.id = '\".$passed_person.\"'\n \";\n $result = mysqli_query($dbh, $query) or die(mysqli_error($dbh));\n\n while ( $line = mysqli_fetch_array($result)) {\n $thisperson['firstname'] = $line['firstname'];\n $thisperson['middlename'] = $line['middlename'];\n $thisperson['lastname'] = $line['lastname'];\n $thisperson['suffix'] = $line['suffix'];\n $thisperson['degree'] = $line['degree'];\n $personcount++;\n }\n\n $schoolinfo = find_persons_school($passed_person);\n $thisperson['dissertation_id'] = $schoolinfo['dissertation_id'];\n $thisperson['completedyear'] = $schoolinfo['completedyear'];\n $thisperson['country'] = $schoolinfo['country'];\n $thisperson['school'] = $schoolinfo['school'];\n $thisperson['schoolid'] = $schoolinfo['schoolid'];\n\n if ($thisperson['dissertation_id'] == \"\")\n {\n $thisperson['status'] = \"\";\n $thisperson['notes'] = \"\";\n $thisperson['title'] = \"N/A\";\n $thisperson['abstract'] = \"N/A\";\n $thisperson['abstract_html'] = \"N/A\";\n }\n else\n {\n $dissertation = find_dissertation($thisperson['dissertation_id']);\n $thisperson['status'] = $dissertation['status'];\n $thisperson['notes'] = $dissertation['notes'];\n $thisperson['discipline_id'] = $dissertation['discipline_id'];\n $thisperson['title'] = $dissertation['title'];\n $thisperson['abstract'] = $dissertation['abstract'];\n $thisperson['abstract_html'] = encode_linebreaks($dissertation['abstract']);\n if ($thisperson['title'] == \"\") { $thisperson['title'] = \"N/A\";}\n if ($thisperson['abstract'] == \"\")\n {\n $thisperson['abstract'] = \"N/A\";\n $thisperson['abstract_html'] = \"N/A\";\n }\n }\n\n $thisperson['advisors'] = find_advisors_for_person($passed_person);\n $thisperson['cmembers'] = find_committee_for_person($passed_person);\n $thisperson['advisorships'] = find_advisorships_under_person($passed_person);\n $thisperson['committeeships'] = find_committeeships_under_person($passed_person);\n\n\n if ($personcount < 1)\n {\n action_box(\"Person \".$passed_person.\" Not Found\");\n }\n else\n {\n\n echo \"
\\n\";\n\n # Name / Aliases\n $count = 0;\n $printme = \"\";\n $fullname = $thisperson['firstname'].\" \".$thisperson['middlename'].\" \".$thisperson['lastname'].\" \".$thisperson['suffix'];\n $printme .= \"

Dissertation Information for $fullname

\";\n $printme .= \"

\";\n if (is_admin())\n {\n if (isset($thisperson['completedyear']))\n {\n $printme .= \" (Edit)\";\n }\n else\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n $printme .= \"
\\n\";\n }\n $printme .= \"

\";\n $printme .= \"

\";\n $printme .= \"NAME: \";\n if (is_admin())\n {\n $printme .= \"(Add)\";\n }\n $printme .= \"
\";\n $printme .= \" - \";\n $printme .= get_person_link($passed_person);\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n $printme .= \"
\\n\";\n\n $aliases = 0;\n foreach (find_aliases($passed_person) as $one)\n {\n $printme .= \" - (Alias) \";\n $printme .= $one['firstname'].\" \";\n $printme .= $one['middlename'].\" \";\n $printme .= $one['lastname'].\" \";\n $printme .= $one['suffix'].\" \";\n if (is_admin())\n {\n $printme .= \"(Set as Primary)\";\n $printme .= \" (Delete)\";\n }\n $printme .= \"
\";\n $aliases++;\n }\n $printme .= \"

\";\n echo $printme;\n\n # Degree\n $printme = \"

\\n\";\n $printme .= \"DEGREE:
\\n\";\n $printme .= \" - \".$thisperson['degree'];\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n $printme .= \"

\";\n echo $printme;\n\n # Discipline\n $printme = \"

\\n\";\n $printme .= \"DISCIPLINE:
\\n\";\n if (isset($thisperson['discipline_id']))\n {\n $discipline = find_discipline($thisperson['discipline_id']);\n $printme .= \" - \".$discipline['title'].\"\";\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n }\n else\n {\n $printme .= \" - None\";\n if (is_admin())\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n }\n $printme .= \"

\";\n echo $printme;\n\n # School\n $printme = \"

\\n\";\n $printme .= \"SCHOOL:
\\n\";\n if (isset($thisperson['completedyear']))\n {\n $printme .= \" - \".$thisperson['school'].\" (\".$thisperson['country'].\") (\".$thisperson['completedyear'].\")\";\n if (is_admin())\n {\n $printme .= \" (Edit)\";\n }\n }\n else\n {\n $printme .= \" - None\";\n if (is_admin())\n {\n $printme .= \" (Create Dissertation for $fullname)\";\n }\n }\n $printme .= \"

\\n\";\n echo $printme;\n\n\n # Advisors\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"ADVISORS: \";\n if (is_admin() && isset($thisperson['completedyear']))\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['advisors'])){\n foreach ($thisperson['advisors'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\";\n echo $printme;\n\n # Committee Members\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"COMMITTEE MEMBERS: \";\n if (is_admin() && isset($thisperson['completedyear']))\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['cmembers'])){\n foreach ($thisperson['cmembers'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\\n\\n\";\n\n # Admin Notes\n if (is_admin())\n {\n if ($thisperson['notes'] != \"\")\n {\n $printme .= \"

\";\n $printme .= \"\\n\";\n $printme .= \"\\n\";\n $printme .= \"
\\n\";\n $printme .= \"Admin Notes: \".$thisperson['notes'].\"
\\n\";\n $printme .= \"
\\n\";\n $printme .= \"

\\n\\n\";\n }\n }\n\n $glossaryterms = find_glossaryterms();\n # Status and Inspection\n $printme .= \"

\";\n $printme .= \"MPACT Status: \".$statuscodes[$thisperson['status']].\"
\\n\";\n $printme .= \"

\\n\\n\";\n\n # Title and Abstract\n $printme .= \"

\";\n $printme .= \"Title: \".$thisperson['title'].\"
\";\n $printme .= \"

\\n\";\n $printme .= \"

\";\n $printme .= \"Abstract: \".$thisperson['abstract_html'].\"
\";\n $printme .= \"

\\n\\n\";\n\n # print it all out...\n echo $printme;\n\n # URLS\n\n if (is_admin())\n {\n $urls = find_urls_by_person($passed_person);\n echo \"

\\n\";\n echo \"REFERENCE URLS\";\n echo \" (Add)\";\n echo \"
\\n\";\n if (count($urls) > 0)\n {\n echo \"\\n\";\n }\n else\n {\n echo \" - None\\n\";\n }\n foreach ($urls as $one)\n {\n echo \"\\n\";\n echo \"\\n\";\n echo \"\\n\";\n }\n if (count($urls) > 0)\n {\n echo \"
Updated: \".$one['updated_at'].\"\";\n echo \" (Edit)\";\n echo \" (Delete)\";\n echo \"
\".$one['url'].\"
\".$one['description'].\"
\\n\";\n }\n echo \"

\\n\";\n }\n\n # EDIT HISTORY\n\n if (is_admin())\n {\n $entries = get_dissertation_history($thisperson['dissertation_id']);\n if (count($entries) > 0)\n {\n echo \"

\\n\";\n echo \"EDIT HISTORY (Show/Hide)\\n\";\n echo \"\";\n echo \"\\n\";\n }\n\n foreach ($entries as $one)\n {\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\";\n echo \"\\n\";\n }\n if (count($entries) > 0)\n {\n echo \"
\".$one['logged_at'].\"\".$one['user'].\"\".$one['message'].\"
\\n\";\n echo \"

\\n\";\n }\n }\n\n\n\n echo \"
\\n\";\n\n # MPACT Scores\n $printme = \"\";\n $printme .= \"

MPACT Scores for $fullname

\";\n $printme .= \"

\";\n $mpact = mpact_scores($passed_person);\n $printme .= $mpact['output'];\n $printme .= \"

\\n\";\n if (is_admin())\n {\n $printme .= \"

(Recalculate)

\";\n }\n echo $printme;\n\n # Draw FamilyTree Graph for this person\n echo \"

Advisors and Advisees Graph

\\n\";\n echo \"

\";\n draw_tree_dotgraph($passed_person);\n echo \"

\";\n\n echo \"
\\n\";\n\n\n # Students\n echo \"

Students under $fullname

\\n\\n\";\n\n # Advisees\n $count = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"ADVISEES: \";\n if (is_admin())\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['advisorships'])){\n foreach ($thisperson['advisorships'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n $schoolinfo = find_persons_school($one);\n if (isset($schoolinfo['completedyear']))\n {\n $printme .= \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\\n\";\n echo $printme;\n\n # Committeeships\n $ccount = 0;\n $printme = \"\";\n $printme .= \"

\";\n $printme .= \"COMMITTEESHIPS: \";\n if (is_admin())\n {\n $printme .= \" (Add)\";\n }\n $printme .= \"
\";\n if (isset($thisperson['committeeships'])){\n foreach ($thisperson['committeeships'] as $one)\n {\n $printme .= \" - \";\n $printme .= get_person_link($one);\n $schoolinfo = find_persons_school($one);\n if (isset($schoolinfo['completedyear']))\n {\n $printme .= \" - \".$schoolinfo['school'].\" (\".$schoolinfo['completedyear'].\")\";\n }\n if (is_admin())\n {\n $printme .= \" (Remove)\";\n }\n $printme .= \"
\";\n $count++;\n }\n }\n if ($count < 1){$printme .= \" - None\";}\n $printme .= \"

\";\n echo $printme;\n\n }\n\n }\n\n\n}\n\n\n?>\n"}} {"repo": "trac-hacks/trac-dashboard", "pr_number": 2, "title": "Unpack one-element tuple correctly", "state": "closed", "merged_at": "2016-08-27T20:14:18Z", "additions": 2, "deletions": 2, "files_changed": ["dashboard/dashboard.py"], "files_before": {"dashboard/dashboard.py": "from trac.core import *\nfrom pkg_resources import resource_filename\nfrom trac.config import Option, IntOption, ListOption, BoolOption\nfrom trac.web.api import IRequestHandler, Href\nfrom trac.util.translation import _\nfrom trac.web.chrome import add_stylesheet, add_script, INavigationContributor, ITemplateProvider\nfrom trac.web.chrome import Chrome\nfrom trac.util.datefmt import utc, to_timestamp\nfrom genshi.template import TemplateLoader\nfrom genshi.filters.transform import Transformer\nfrom trac.web.api import ITemplateStreamFilter\nfrom trac.perm import IPermissionRequestor\nfrom trac.util import escape, Markup\n\nimport time\nfrom datetime import datetime, timedelta\n\n\n\n\nclass DashBoard(Component):\n implements(IRequestHandler, ITemplateProvider, IPermissionRequestor, INavigationContributor)\n \n permission = Option('dashboard', 'permission', '')\n default_milestone = Option('dashboard', 'default_milestone', '')\n\n def __init__(self):\n self.db = self.env.get_db_cnx()\n self.username = None\n self.backDate = 30\n self.ticket_closed = ['checkedin', 'closed']\n\n self.ticket_closed_sql = \"','\".join(self.ticket_closed)\n\n self.milestone = self.default_milestone\n \n if self.permission:\n self.perm = self.permission\n else:\n self.perm = 'DASHBOARD_VIEW'\n\n self.env.log.debug(\"Using Permission: %s\" % self.permission)\n\n \n # INavigationContributor methods\n def get_active_navigation_item(self, req):\n return 'dashboard'\n\n def get_navigation_items(self, req):\n if self.perm in req.perm or 'TRAC_ADMIN' in req.perm:\n yield 'mainnav', 'dashboard', Markup('Dashboard' % (\n self.env.href.dashboard() ) )\n\n\n\n def get_permission_actions(self):\n yield self.perm\n\n \n # IRequestHandler methods\n def match_request(self, req):\n serve = False\n self.env.log.debug(\"Match Request\")\n\n\n uri = req.path_info.lstrip('/').split('/')\n if uri[0] == 'dashboard':\n serve = True\n\n self.env.log.debug(\"Handle Request: %s\" % serve)\n self.baseURL = req.href('dashboard', '/')\n self.baseQueryURL = req.href('query', '/')\n self.username = req.authname\n if 'milestone' in req.args:\n self.milestone = req.args.get('milestone')\n else:\n self.milestone = self.default_milestone\n\n if self.milestone == '':\n cursor = self.db.cursor()\n sql = \"select name from milestone where (completed = 0) limit 0, 1\"\n cursor.execute(sql)\n for name in cursor:\n self.milestone = name\n\n if 'dev' in req.args:\n self.username = req.args.get('dev')\n else:\n self.username = req.authname\n\n return serve\n\n if not self.perm in req.perm:\n self.env.log.debug(\"NO Permission to view\")\n return False\n\n return serve\n \n def get_updated_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status from ticket where (owner = '%s') and (changetime >= %s) and (status not in ('%s', 'new')) order by changetime desc\" % (self.username, self.stamp, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_new_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, status, component, summary, changetime, priority from ticket where (owner = '%s') and (status in ('new', 'assigned')) and (type = 'defect') order by changetime desc\" % self.username\n cursor.execute(sql)\n out = []\n idx = 0\n for id, status, component, summary, changetime, priority in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'status': status,\n 'component': component,\n 'summary': summary,\n 'priority': priority,\n 'changetime': datetime.fromtimestamp(changetime, utc)\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_closed_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, changetime, status from ticket where (owner = '%s') and (status in ('%s')) and (changetime >= %s) order by component, status, changetime desc\" % (self.username, self.ticket_closed_sql, self.stamp)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, changetime, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status,\n 'changetime': datetime.fromtimestamp(changetime, utc)\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_milestone_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status, priority from ticket where (owner = '%s') and (status not in ('%s', 'new')) and (type in ('defect', 'enhancement')) and (milestone = '%s') order by component, priority\" % (self.username, self.ticket_closed_sql, self.milestone)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status, priority in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status,\n 'priority': priority\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_todo_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status from ticket where (owner = '%s') and (status not in ('%s')) and (type = 'task') order by changetime desc\" % (self.username, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_ticket_counts(self):\n cursor = self.db.cursor()\n sql = \"select count(*) as total, type, status from ticket where (owner = '%s') and (status not in ('%s')) group by type, status order by total desc\" % (self.username, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for total, type, status in cursor:\n data = {\n '__idx__': idx,\n 'total': total,\n 'status': status,\n 'type': type\n }\n idx = idx + 1\n out.append(data)\n\n return out\n\n def get_action_counts(self):\n cursor = self.db.cursor()\n #sql = \"select count(*) as total, concat(oldvalue, ' => ', newvalue) as status from ticket_change where (author = '%s') and (time > %s) and (field = 'status') group by status order by total desc\" % (self.username, self.stamp)\n sql = \"select count(*) as total, (%s) as status from ticket_change where (author = '%s') and (time > %s) and (field = 'status') group by status order by total desc\" % (self.db.concat('oldvalue', \"' => '\", 'newvalue'), self.username, self.stamp)\n cursor.execute(sql)\n \n out = []\n idx = 0\n for total, status in cursor:\n data = {\n '__idx__': idx,\n 'total': total,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n\n return out\n\n\n def get_milestone_data(self):\n cursor = self.db.cursor()\n out = {\n 'total': 0,\n 'closed': 0,\n 'closed_percent': 0,\n 'new': 0,\n 'new_percent': 0,\n 'inprogress': 0,\n 'inprogress_percent': 0,\n 'name': self.milestone\n }\n #sql = \"select count(*) as total, ticket.status from ticket, ticket_custom where (ticket.milestone = '%s') and (ticket.owner = '%s') and (ticket.id = ticket_custom.ticket) and (ticket_custom.name = 'location') and (ticket_custom.value = 'Library Code')\" % (self.milestone, self.username)\n sql = \"select count(*) as total, status from ticket where (milestone = '%s') and (owner = '%s') and (type = 'defect') group by status\" % (self.milestone, self.username)\n cursor.execute(sql)\n\n for total, status in cursor:\n out['total'] = out['total'] + total\n\n if status in self.ticket_closed:\n out['closed'] = out['closed'] + total\n elif status == 'new':\n out['new'] = out['new'] + total\n else:\n out['inprogress'] = out['inprogress'] + total\n\n if out['closed'] > 0:\n out['closed_percent'] = int(round((float(out['closed']) / out['total']), 3) * 100)\n\n if out['new'] > 0:\n out['new_percent'] = int(round((float(out['new']) / out['total']), 1) * 100)\n\n if out['inprogress'] > 0:\n out['inprogress_percent'] = int(round((float(out['inprogress']) / out['total']), 3) * 100)\n\n\n return out\n\n def get_milestones(self):\n cursor = self.db.cursor()\n sql = \"select name from milestone where (name not in ('%s')) and (completed = 0)\" % self.milestone\n cursor.execute(sql)\n data = []\n for name in cursor:\n data.append(name)\n\n return data\n\n def get_users(self):\n devs = self.env.get_known_users()\n odevs = []\n for username,name,email in devs:\n if username != self.username:\n data = {\n 'username': username,\n 'name': name or username\n }\n odevs.append(data)\n return odevs\n\n\n def process_request(self, req):\n data = {}\n self.stamp = time.time() - (60 * 60 * 24 * self.backDate)\n today = datetime.now(req.tz)\n\n\n data['backDate'] = self.backDate\n data['stamp'] = self.stamp\n data['username'] = self.username\n data['milestone'] = self.milestone\n\n #Updated Tickets \n data['updated_tickets'] = self.get_updated_tickets()\n data['has_updated_tickets'] = len(data['updated_tickets'])\n\n #New Tickets\n data['new_tickets'] = self.get_new_tickets()\n data['has_new_tickets'] = len(data['new_tickets'])\n\n #Closed Tickets\n data['closed_tickets'] = self.get_closed_tickets()\n data['has_closed_tickets'] = len(data['closed_tickets'])\n\n #Ticket Counts\n data['ticket_counts'] = self.get_ticket_counts()\n data['has_ticket_counts'] = len(data['ticket_counts'])\n\n #Action Counts\n data['action_counts'] = self.get_action_counts()\n data['has_action_counts'] = len(data['action_counts'])\n\n #TODO Lists\n data['todo_tickets'] = self.get_todo_tickets()\n data['has_todo_tickets'] = len(data['todo_tickets'])\n\n #Milestones\n data['milestone_data'] = self.get_milestone_data()\n data['has_milestones'] = len(data['milestone_data'])\n\n #Milestone Tickets\n data['milestone_tickets'] = self.get_milestone_tickets()\n data['has_milestone_tickets'] = len(data['milestone_tickets'])\n\n #Milestones\n data['milestones'] = self.get_milestones()\n\n #Users\n data['users'] = self.get_users()\n\n\n add_script(req, \"dashboard/dashboard.js\")\n add_stylesheet(req, \"dashboard/dashboard.css\")\n return 'dashboard.html', data, None\n\n\n def get_htdocs_dirs(self):\n \"\"\"Return the absolute path of a directory containing additional\n static resources (such as images, style sheets, etc).\n \"\"\"\n return [('dashboard', resource_filename(__name__, 'htdocs'))]\n \n def get_templates_dirs(self):\n \"\"\"Return the absolute path of the directory containing the provided\n genshi templates.\n \"\"\"\n rtn = [resource_filename(__name__, 'templates')]\n return rtn\n"}, "files_after": {"dashboard/dashboard.py": "from trac.core import *\nfrom pkg_resources import resource_filename\nfrom trac.config import Option, IntOption, ListOption, BoolOption\nfrom trac.web.api import IRequestHandler, Href\nfrom trac.util.translation import _\nfrom trac.web.chrome import add_stylesheet, add_script, INavigationContributor, ITemplateProvider\nfrom trac.web.chrome import Chrome\nfrom trac.util.datefmt import utc, to_timestamp\nfrom genshi.template import TemplateLoader\nfrom genshi.filters.transform import Transformer\nfrom trac.web.api import ITemplateStreamFilter\nfrom trac.perm import IPermissionRequestor\nfrom trac.util import escape, Markup\n\nimport time\nfrom datetime import datetime, timedelta\n\n\n\n\nclass DashBoard(Component):\n implements(IRequestHandler, ITemplateProvider, IPermissionRequestor, INavigationContributor)\n \n permission = Option('dashboard', 'permission', '')\n default_milestone = Option('dashboard', 'default_milestone', '')\n\n def __init__(self):\n self.db = self.env.get_db_cnx()\n self.username = None\n self.backDate = 30\n self.ticket_closed = ['checkedin', 'closed']\n\n self.ticket_closed_sql = \"','\".join(self.ticket_closed)\n\n self.milestone = self.default_milestone\n \n if self.permission:\n self.perm = self.permission\n else:\n self.perm = 'DASHBOARD_VIEW'\n\n self.env.log.debug(\"Using Permission: %s\" % self.permission)\n\n \n # INavigationContributor methods\n def get_active_navigation_item(self, req):\n return 'dashboard'\n\n def get_navigation_items(self, req):\n if self.perm in req.perm or 'TRAC_ADMIN' in req.perm:\n yield 'mainnav', 'dashboard', Markup('Dashboard' % (\n self.env.href.dashboard() ) )\n\n\n\n def get_permission_actions(self):\n yield self.perm\n\n \n # IRequestHandler methods\n def match_request(self, req):\n serve = False\n self.env.log.debug(\"Match Request\")\n\n\n uri = req.path_info.lstrip('/').split('/')\n if uri[0] == 'dashboard':\n serve = True\n\n self.env.log.debug(\"Handle Request: %s\" % serve)\n self.baseURL = req.href('dashboard', '/')\n self.baseQueryURL = req.href('query', '/')\n self.username = req.authname\n if 'milestone' in req.args:\n self.milestone = req.args.get('milestone')\n else:\n self.milestone = self.default_milestone\n\n if self.milestone == '':\n cursor = self.db.cursor()\n sql = \"select name from milestone where (completed = 0) limit 0, 1\"\n cursor.execute(sql)\n for name, in cursor:\n self.milestone = name\n\n if 'dev' in req.args:\n self.username = req.args.get('dev')\n else:\n self.username = req.authname\n\n return serve\n\n if not self.perm in req.perm:\n self.env.log.debug(\"NO Permission to view\")\n return False\n\n return serve\n \n def get_updated_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status from ticket where (owner = '%s') and (changetime >= %s) and (status not in ('%s', 'new')) order by changetime desc\" % (self.username, self.stamp, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_new_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, status, component, summary, changetime, priority from ticket where (owner = '%s') and (status in ('new', 'assigned')) and (type = 'defect') order by changetime desc\" % self.username\n cursor.execute(sql)\n out = []\n idx = 0\n for id, status, component, summary, changetime, priority in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'status': status,\n 'component': component,\n 'summary': summary,\n 'priority': priority,\n 'changetime': datetime.fromtimestamp(changetime, utc)\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_closed_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, changetime, status from ticket where (owner = '%s') and (status in ('%s')) and (changetime >= %s) order by component, status, changetime desc\" % (self.username, self.ticket_closed_sql, self.stamp)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, changetime, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status,\n 'changetime': datetime.fromtimestamp(changetime, utc)\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_milestone_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status, priority from ticket where (owner = '%s') and (status not in ('%s', 'new')) and (type in ('defect', 'enhancement')) and (milestone = '%s') order by component, priority\" % (self.username, self.ticket_closed_sql, self.milestone)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status, priority in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status,\n 'priority': priority\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_todo_tickets(self):\n cursor = self.db.cursor()\n sql = \"select id, component, summary, status from ticket where (owner = '%s') and (status not in ('%s')) and (type = 'task') order by changetime desc\" % (self.username, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for id, component, summary, status in cursor:\n data = {\n '__idx__': idx,\n 'id': id,\n 'component': component,\n 'summary': summary,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n return out\n\n def get_ticket_counts(self):\n cursor = self.db.cursor()\n sql = \"select count(*) as total, type, status from ticket where (owner = '%s') and (status not in ('%s')) group by type, status order by total desc\" % (self.username, self.ticket_closed_sql)\n cursor.execute(sql)\n out = []\n idx = 0\n for total, type, status in cursor:\n data = {\n '__idx__': idx,\n 'total': total,\n 'status': status,\n 'type': type\n }\n idx = idx + 1\n out.append(data)\n\n return out\n\n def get_action_counts(self):\n cursor = self.db.cursor()\n #sql = \"select count(*) as total, concat(oldvalue, ' => ', newvalue) as status from ticket_change where (author = '%s') and (time > %s) and (field = 'status') group by status order by total desc\" % (self.username, self.stamp)\n sql = \"select count(*) as total, (%s) as status from ticket_change where (author = '%s') and (time > %s) and (field = 'status') group by status order by total desc\" % (self.db.concat('oldvalue', \"' => '\", 'newvalue'), self.username, self.stamp)\n cursor.execute(sql)\n \n out = []\n idx = 0\n for total, status in cursor:\n data = {\n '__idx__': idx,\n 'total': total,\n 'status': status\n }\n idx = idx + 1\n out.append(data)\n\n return out\n\n\n def get_milestone_data(self):\n cursor = self.db.cursor()\n out = {\n 'total': 0,\n 'closed': 0,\n 'closed_percent': 0,\n 'new': 0,\n 'new_percent': 0,\n 'inprogress': 0,\n 'inprogress_percent': 0,\n 'name': self.milestone\n }\n #sql = \"select count(*) as total, ticket.status from ticket, ticket_custom where (ticket.milestone = '%s') and (ticket.owner = '%s') and (ticket.id = ticket_custom.ticket) and (ticket_custom.name = 'location') and (ticket_custom.value = 'Library Code')\" % (self.milestone, self.username)\n sql = \"select count(*) as total, status from ticket where (milestone = '%s') and (owner = '%s') and (type = 'defect') group by status\" % (self.milestone, self.username)\n cursor.execute(sql)\n\n for total, status in cursor:\n out['total'] = out['total'] + total\n\n if status in self.ticket_closed:\n out['closed'] = out['closed'] + total\n elif status == 'new':\n out['new'] = out['new'] + total\n else:\n out['inprogress'] = out['inprogress'] + total\n\n if out['closed'] > 0:\n out['closed_percent'] = int(round((float(out['closed']) / out['total']), 3) * 100)\n\n if out['new'] > 0:\n out['new_percent'] = int(round((float(out['new']) / out['total']), 1) * 100)\n\n if out['inprogress'] > 0:\n out['inprogress_percent'] = int(round((float(out['inprogress']) / out['total']), 3) * 100)\n\n\n return out\n\n def get_milestones(self):\n cursor = self.db.cursor()\n sql = \"select name from milestone where (name not in ('%s')) and (completed = 0)\" % self.milestone\n cursor.execute(sql)\n data = []\n for name, in cursor:\n data.append(name)\n\n return data\n\n def get_users(self):\n devs = self.env.get_known_users()\n odevs = []\n for username,name,email in devs:\n if username != self.username:\n data = {\n 'username': username,\n 'name': name or username\n }\n odevs.append(data)\n return odevs\n\n\n def process_request(self, req):\n data = {}\n self.stamp = time.time() - (60 * 60 * 24 * self.backDate)\n today = datetime.now(req.tz)\n\n\n data['backDate'] = self.backDate\n data['stamp'] = self.stamp\n data['username'] = self.username\n data['milestone'] = self.milestone\n\n #Updated Tickets \n data['updated_tickets'] = self.get_updated_tickets()\n data['has_updated_tickets'] = len(data['updated_tickets'])\n\n #New Tickets\n data['new_tickets'] = self.get_new_tickets()\n data['has_new_tickets'] = len(data['new_tickets'])\n\n #Closed Tickets\n data['closed_tickets'] = self.get_closed_tickets()\n data['has_closed_tickets'] = len(data['closed_tickets'])\n\n #Ticket Counts\n data['ticket_counts'] = self.get_ticket_counts()\n data['has_ticket_counts'] = len(data['ticket_counts'])\n\n #Action Counts\n data['action_counts'] = self.get_action_counts()\n data['has_action_counts'] = len(data['action_counts'])\n\n #TODO Lists\n data['todo_tickets'] = self.get_todo_tickets()\n data['has_todo_tickets'] = len(data['todo_tickets'])\n\n #Milestones\n data['milestone_data'] = self.get_milestone_data()\n data['has_milestones'] = len(data['milestone_data'])\n\n #Milestone Tickets\n data['milestone_tickets'] = self.get_milestone_tickets()\n data['has_milestone_tickets'] = len(data['milestone_tickets'])\n\n #Milestones\n data['milestones'] = self.get_milestones()\n\n #Users\n data['users'] = self.get_users()\n\n\n add_script(req, \"dashboard/dashboard.js\")\n add_stylesheet(req, \"dashboard/dashboard.css\")\n return 'dashboard.html', data, None\n\n\n def get_htdocs_dirs(self):\n \"\"\"Return the absolute path of a directory containing additional\n static resources (such as images, style sheets, etc).\n \"\"\"\n return [('dashboard', resource_filename(__name__, 'htdocs'))]\n \n def get_templates_dirs(self):\n \"\"\"Return the absolute path of the directory containing the provided\n genshi templates.\n \"\"\"\n rtn = [resource_filename(__name__, 'templates')]\n return rtn\n"}} {"repo": "lowendbox/lowendscript", "pr_number": 12, "title": "Added functionality for Drupal installation, made readme file, and fixed some bugs.", "state": "open", "merged_at": null, "additions": 524, "deletions": 24, "files_changed": ["setup-debian.sh"], "files_before": {"setup-debian.sh": "#!/bin/bash\n\nfunction check_install {\n if [ -z \"`which \"$1\" 2>/dev/null`\" ]\n then\n executable=$1\n shift\n while [ -n \"$1\" ]\n do\n DEBIAN_FRONTEND=noninteractive apt-get -q -y install \"$1\"\n print_info \"$1 installed for $executable\"\n shift\n done\n else\n print_warn \"$2 already installed\"\n fi\n}\n\nfunction check_remove {\n if [ -n \"`which \"$1\" 2>/dev/null`\" ]\n then\n DEBIAN_FRONTEND=noninteractive apt-get -q -y remove --purge \"$2\"\n print_info \"$2 removed\"\n else\n print_warn \"$2 is not installed\"\n fi\n}\n\nfunction check_sanity {\n # Do some sanity checking.\n if [ $(/usr/bin/id -u) != \"0\" ]\n then\n die 'Must be run by root user'\n fi\n\n if [ ! -f /etc/debian_version ]\n then\n die \"Distribution is not supported\"\n fi\n}\n\nfunction die {\n echo \"ERROR: $1\" > /dev/null 1>&2\n exit 1\n}\n\nfunction get_domain_name() {\n # Getting rid of the lowest part.\n domain=${1%.*}\n lowest=`expr \"$domain\" : '.*\\.\\([a-z][a-z]*\\)'`\n case \"$lowest\" in\n com|net|org|gov|edu|co)\n domain=${domain%.*}\n ;;\n esac\n lowest=`expr \"$domain\" : '.*\\.\\([a-z][a-z]*\\)'`\n [ -z \"$lowest\" ] && echo \"$domain\" || echo \"$lowest\"\n}\n\nfunction get_password() {\n # Check whether our local salt is present.\n SALT=/var/lib/radom_salt\n if [ ! -f \"$SALT\" ]\n then\n head -c 512 /dev/urandom > \"$SALT\"\n chmod 400 \"$SALT\"\n fi\n password=`(cat \"$SALT\"; echo $1) | md5sum | base64`\n echo ${password:0:13}\n}\n\nfunction install_dash {\n check_install dash dash\n rm -f /bin/sh\n ln -s dash /bin/sh\n}\n\nfunction install_dropbear {\n check_install dropbear dropbear\n check_install /usr/sbin/xinetd xinetd\n\n # Disable SSH\n touch /etc/ssh/sshd_not_to_be_run\n invoke-rc.d ssh stop\n\n # Enable dropbear to start. We are going to use xinetd as it is just\n # easier to configure and might be used for other things.\n cat > /etc/xinetd.d/dropbear < /etc/mysql/conf.d/lowendbox.cnf < ~/.my.cnf < /etc/nginx/conf.d/lowendbox.conf < /etc/init.d/php-cgi <&2\n exit 1\n ;;\nesac\nexit 0\nEND\n chmod 755 /etc/init.d/php-cgi\n mkdir -p /var/run/www\n chown www-data:www-data /var/run/www\n\n cat > /etc/nginx/fastcgi_php < /etc/syslog.conf < /etc/logrotate.d/inetutils-syslogd </dev/null\n endscript\n}\nEND\n\n invoke-rc.d inetutils-syslogd start\n}\n\nfunction install_wordpress {\n check_install wget wget\n if [ -z \"$1\" ]\n then\n die \"Usage: `basename $0` wordpress \"\n fi\n\n # Downloading the WordPress' latest and greatest distribution.\n mkdir /tmp/wordpress.$$\n wget -O - http://wordpress.org/latest.tar.gz | \\\n tar zxf - -C /tmp/wordpress.$$\n mv /tmp/wordpress.$$/wordpress \"/var/www/$1\"\n rm -rf /tmp/wordpress.$$\n chown root:root -R \"/var/www/$1\"\n\n # Setting up the MySQL database\n dbname=`echo $1 | tr . _`\n userid=`get_domain_name $1`\n # MySQL userid cannot be more than 15 characters long\n userid=\"${userid:0:15}\"\n passwd=`get_password \"$userid@mysql\"`\n cp \"/var/www/$1/wp-config-sample.php\" \"/var/www/$1/wp-config.php\"\n sed -i \"s/database_name_here/$dbname/; s/username_here/$userid/; s/password_here/$passwd/\" \\\n \"/var/www/$1/wp-config.php\"\n mysqladmin create \"$dbname\"\n echo \"GRANT ALL PRIVILEGES ON \\`$dbname\\`.* TO \\`$userid\\`@localhost IDENTIFIED BY '$passwd';\" | \\\n mysql\n\n # Setting up Nginx mapping\n cat > \"/etc/nginx/sites-enabled/$1.conf\" <&2\n exit 1\nfi\n\nfunction check_install {\n if [ -z \"`which \"$1\" 2>/dev/null`\" ]\n then\n executable=$1\n shift\n while [ -n \"$1\" ]\n do\n DEBIAN_FRONTEND=noninteractive apt-get -q -y install \"$1\"\n print_info \"$1 installed for $executable\"\n shift\n done\n else\n print_warn \"$2 already installed\"\n fi\n}\n\nfunction check_remove {\n if [ -n \"`which \"$1\" 2>/dev/null`\" ]\n then\n DEBIAN_FRONTEND=noninteractive apt-get -q -y remove --purge \"$2\"\n print_info \"$2 removed\"\n else\n print_warn \"$2 is not installed\"\n fi\n}\n\nfunction check_sanity {\n # Do some sanity checking.\n if [ $(/usr/bin/id -u) != \"0\" ]\n then\n die 'Must be run by root user'\n fi\n\n if [ ! -f /etc/debian_version ]\n then\n die \"Distribution is not supported\"\n fi\n}\n\nfunction die {\n echo \"ERROR: $1\" > /dev/null 1>&2\n exit 1\n}\n\nfunction get_domain_name() {\n # Getting rid of the lowest part.\n domain=${1%.*}\n lowest=`expr \"$domain\" : '.*\\.\\([a-z][a-z]*\\)'`\n case \"$lowest\" in\n com|net|org|gov|edu|co)\n domain=${domain%.*}\n ;;\n esac\n lowest=`expr \"$domain\" : '.*\\.\\([a-z][a-z]*\\)'`\n [ -z \"$lowest\" ] && echo \"$domain\" || echo \"$lowest\"\n}\n\nfunction get_password() {\n # Check whether our local salt is present.\n SALT=/var/lib/radom_salt\n if [ ! -f \"$SALT\" ]\n then\n head -c 512 /dev/urandom > \"$SALT\"\n chmod 400 \"$SALT\"\n fi\n password=`(cat \"$SALT\"; echo $1) | md5sum | base64`\n echo ${password:0:13}\n}\n\nfunction install_dash {\n check_install dash dash\n rm -f /bin/sh\n ln -s dash /bin/sh\n}\n\nfunction install_htop {\n check_install htop htop\n}\n\nfunction install_smart {\n\tcheck_install smartmontools smartmontools\n}\n\nfunction install_locate {\n check_install locate locate\n}\n\nfunction fix_locale {\n dpkg-reconfigure locales\n}\n\nfunction var_www {\n mkdir -p /var/www/\n}\n\nfunction install_dropbear {\n check_install dropbear dropbear\n check_install /usr/sbin/xinetd xinetd\n\n # Disable SSH\n touch /etc/ssh/sshd_not_to_be_run\n invoke-rc.d ssh stop\n\n # Enable dropbear to start. We are going to use xinetd as it is just\n # easier to configure and might be used for other things.\n cat > /etc/xinetd.d/dropbear < /etc/mysql/conf.d/lowendbox.cnf < ~/.my.cnf < /etc/nginx/conf.d/lowendbox.conf < /etc/init.d/php-cgi <&2\n exit 1\n ;;\nesac\nexit 0\nEND\n chmod 755 /etc/init.d/php-cgi\n mkdir -p /var/lib/www\n chown www-data:www-data /var/lib/www\n\n cat > /etc/nginx/fastcgi_php < /etc/syslog.conf < /etc/logrotate.d/inetutils-syslogd </dev/null\n endscript\n}\nEND\n\n invoke-rc.d inetutils-syslogd start\n}\n\nfunction install_wordpress {\n# Needs fixing, soon!!!\n check_install wget wget\n if [ -z \"$1\" ]\n then\n die \"Usage: `basename $0` wordpress \"\n fi\n\n # Downloading the WordPress' latest and greatest distribution.\n mkdir /tmp/wordpress.$$\n wget -O - http://wordpress.org/latest.tar.gz | \\\n tar zxf - -C /tmp/wordpress.$$\n\tmkdir -p /var/www/$1\n mv /tmp/wordpress.$$/wordpress/* \"/var/www/$1\"\n rm -rf /tmp/wordpress.$$\n chown root:root -R \"/var/www/$1\"\n\n # Setting up the MySQL database\n dbname=`echo $1 | tr . _`\n\techo Database Name = 'echo $1 | tr . _'\n userid=`get_domain_name $1`\n # MySQL userid cannot be more than 15 characters long\n userid=\"${userid:0:15}\"\n passwd=`get_password \"$userid@mysql\"`\n cp \"/var/www/$1/wp-config-sample.php\" \"/var/www/$1/wp-config.php\"\n sed -i \"s/database_name_here/$dbname/; s/username_here/$userid/; s/password_here/$passwd/\" \\\n \"/var/www/$1/wp-config.php\"\n mysqladmin create \"$dbname\"\n echo \"GRANT ALL PRIVILEGES ON \\`$dbname\\`.* TO \\`$userid\\`@localhost IDENTIFIED BY '$passwd';\" | \\\n mysql\n\n # Setting up Nginx mapping\n cat > \"/etc/nginx/sites-enabled/$1.conf\" < \"/usr/share/nginx/www/$1/index.html\" < \"/etc/nginx/sites-enabled/$1.conf\" <\"\n fi\n\t\n\t#Download PHP5-gd package\n\tapt-get -q -y install php5-gd\n /etc/init.d/php-cgi restart\n\t\n # Downloading the Drupal' latest and greatest distribution.\n mkdir /tmp/drupal.$$\n wget -O - http://ftp.drupal.org/files/projects/drupal-6.30.tar.gz | \\\n tar zxf - -C /tmp/drupal.$$/\n mkdir -p /var/www/$1\n cp -Rf /tmp/drupal.$$/drupal*/* \"/var/www/$1\"\n rm -rf /tmp/drupal*\n chown root:root -R \"/var/www/$1\"\n\n # Setting up the MySQL database\n dbname=`echo $1 | tr . _`\n\t\n\t# MySQL dbname cannot be more than 15 characters long\n dbname=\"${dbname:0:15}\"\n \n\tuserid=`get_domain_name $1`\n \n\t# MySQL userid cannot be more than 15 characters long\n userid=\"${userid:0:15}\"\n passwd=`get_password \"$userid@mysql\"`\n cp \"/var/www/$1/sites/default/default.settings.php\" \"/var/www/$1/sites/default/settings.php\"\n\tchmod 777 /var/www/$1/sites/default/settings.php\n\tmkdir /var/www/$1/sites/default/files\n\tchmod -R 777 /var/www/$1/sites/default/files\n mysqladmin create \"$dbname\"\n echo \"GRANT ALL PRIVILEGES ON \\`$dbname\\`.* TO \\`$userid\\`@localhost IDENTIFIED BY '$passwd';\" | \\\n mysql\n\n\t#Copy DB Name, User, and Pass to settings.php and set to read only.\n\tsed -i \"91 s/username/$userid/; 91 s/password/$passwd/; 91 s/databasename/$dbname/\" \"/var/www/$1/sites/default/settings.php\"\n\tchmod 644 /var/www/$1/sites/default/settings.php\n \n\t# Setting up Nginx mapping\n cat > \"/etc/nginx/sites-enabled/$1.conf\" <\"\n fi\n\t\n\t#Download PHP5-gd package\n\tapt-get -q -y install php5-gd\n /etc/init.d/php-cgi restart\n\t\n # Downloading the Drupal' latest and greatest distribution.\n mkdir /tmp/drupal.$$\n wget -O - http://ftp.drupal.org/files/projects/drupal-7.26.tar.gz | \\\n tar zxf - -C /tmp/drupal.$$/\n mkdir -p /var/www/$1\n cp -Rf /tmp/drupal.$$/drupal*/* \"/var/www/$1\"\n rm -rf /tmp/drupal*\n chown root:root -R \"/var/www/$1\"\n\n # Setting up the MySQL database\n dbname=`echo $1 | tr . _`\n\t\n\t# MySQL dbname cannot be more than 15 characters long\n dbname=\"${dbname:0:15}\"\n\t\n userid=`get_domain_name $1`\n\t\n # MySQL userid cannot be more than 15 characters long\n userid=\"${userid:0:15}\"\n passwd=`get_password \"$userid@mysql\"`\n\t\n\t# Copy default.settings.php to settings.php and set write permissions.\n cp \"/var/www/$1/sites/default/default.settings.php\" \"/var/www/$1/sites/default/settings.php\"\n\tchmod 777 /var/www/$1/sites/default/settings.php\n\tmkdir /var/www/$1/sites/default/files\n\tchmod -R 777 /var/www/$1/sites/default/files\n \n\t# Create MySQL database\n\tmysqladmin create \"$dbname\"\n echo \"GRANT ALL PRIVILEGES ON \\`$dbname\\`.* TO \\`$userid\\`@localhost IDENTIFIED BY '$passwd';\" | \\\n mysql\n\t\t\n #Copy DB Name, User, and Pass to settings.php and set to read only.\n echo \"\\$databases['default']['default'] = array(\" >> /var/www/$1/sites/default/settings.php\n echo \"'driver' => 'mysql',\" >> /var/www/$1/sites/default/settings.php\n echo \"'database' => '$dbname',\" >> /var/www/$1/sites/default/settings.php\n echo \"'username' => '$userid',\" >> /var/www/$1/sites/default/settings.php\n echo \"'password' => '$passwd',\" >> /var/www/$1/sites/default/settings.php\n echo \"'host' => 'localhost');\" >> /var/www/$1/sites/default/settings.php\n chmod 644 /var/www/$1/sites/default/settings.php\n\t\n\t#Echo DB Name\n\techo -e $COL_BLUE\"*** COPY FOR SAFE KEEPING ***\"\n\tCOL_BLUE=\"\\x1b[34;01m\"\n COL_RESET=\"\\x1b[39;49;00m\"\n echo -e $COL_BLUE\"Database Name: \"$COL_RESET\"$dbname\"\n\t\n #Echo DB User value\n\techo -e $COL_BLUE\"Database User: \"$COL_RESET\"${userid:0:15}\"\n\t\n\t#Echo DB Password\n\techo -e $COL_BLUE\"Database Password: \"$COL_RESET\"$passwd\"\n\t\n\t#Echo Install URL\n\techo -e $COL_BLUE\"Visit to finalize installation: \"$COL_RESET\"http://$1/install.php\"\n\t\n\n\n # Setting up Nginx mapping\n cat > \"/etc/nginx/sites-enabled/$1.conf\" <args = $args;\n\t\t\n\t\tif (!$this->args[\"username\"]){\n\t\t\tthrow new exception(\"No username was given.\");\n\t\t}\n\t\t\n\t\tif (!$this->args[\"password\"]){\n\t\t\tthrow new exception(\"No password was given.\");\n\t\t}\n\t\t\n\t\trequire_once \"knj/http.php\";\n\t\t$this->http = new knj_httpbrowser();\n\t\t$this->http->connect(\"betaling.wannafind.dk\", 443);\n\t\t\n\t\t$html = $this->http->getaddr(\"index.php\");\n\t\t\n\t\t$html = $this->http->post(\"pg.loginauth.php\", array(\n\t\t\t\"username\" => $this->args[\"username\"],\n\t\t\t\"password\" => $this->args[\"password\"]\n\t\t));\n\t\t\n\t\tif (strpos($html, \"Brugernavn eller password, blev ikke godkendt.\") !== false){\n\t\t\tthrow new exception(\"Could not log in.\");\n\t\t}\n\t}\n\t\n\tfunction http(){\n\t\treturn $this->http;\n\t}\n\t\n\tfunction listPayments($args = array()){\n\t\tif ($args[\"awaiting\"]){\n\t\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactions.php\");\n\t\t}else{\n\t\t\t$sargs = array(\n\t\t\t\t\"searchtype\" => \"\",\n\t\t\t\t\"fromday\" => \"01\",\n\t\t\t\t\"frommonth\" => \"01\",\n\t\t\t\t\"fromyear\" => date(\"Y\"),\n\t\t\t\t\"today\" => \"31\",\n\t\t\t\t\"tomonth\" => \"12\",\n\t\t\t\t\"toyear\" => date(\"Y\"),\n\t\t\t\t\"transacknum\" => \"\"\n\t\t\t);\n\t\t\t\n\t\t\tif ($args[\"order_id\"]){\n\t\t\t\t$sargs[\"orderid\"] = $args[\"order_id\"];\n\t\t\t}\n\t\t\t\n\t\t\t$html = $this->http->post(\"pg.frontend/pg.search.php?search=doit\", $sargs);\n\t\t}\n\t\t\n\t\tif (!preg_match_all(\"/([0-9]+)<\\/a><\\/td>\\s*(.+)<\\/td>\\s*(.+)<\\/td>\\s*(.+)<\\/td>\\s*.*<\\/td>\\s*(.*)<\\/td>\\s*(.*)<\\/td>/U\", $html, $matches)){\n\t\t\treturn array(); //no payments were found - return empty array.\n\t\t\t//echo $html . \"\\n\\n\";\n\t\t\tthrow new exception(\"Could not parse payments.\");\n\t\t}\n\t\t\n\t\t$payments = array();\n\t\tforeach($matches[0] AS $key => $value){\n\t\t\t$id = $matches[1][$key];\n\t\t\t\n\t\t\t$amount = str_replace(\" DKK\", \"\", $matches[6][$key]);\n\t\t\t$amount = strtr($amount, array(\n\t\t\t\t\".\" => \"\",\n\t\t\t\t\",\" => \".\"\n\t\t\t));\n\t\t\t\n\t\t\t$card_type = $matches[7][$key];\n\t\t\tif (strpos($card_type, \"dk.png\") !== false){\n\t\t\t\t$card_type = \"dk\";\n\t\t\t}elseif(strpos($card_type, \"visa-elec.png\") !== false){\n\t\t\t\t$card_type = \"visa_electron\";\n\t\t\t}elseif(strpos($card_type, \"mc.png\") !== false){\n\t\t\t\t$card_type = \"mastercard\";\n\t\t\t}elseif(strpos($card_type, \"visa.png\") !== false){\n\t\t\t\t$card_type = \"visa\";\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Unknown card-type image: \" . $card_type);\n\t\t\t}\n\t\t\t\n\t\t\t$date = strtr($matches[5][$key], array(\n\t\t\t\t\"januar\" => 1,\n\t\t\t\t\"februar\" => 2,\n\t\t\t\t\"marts\" => 3,\n\t\t\t\t\"april\" => 4,\n\t\t\t\t\"maj\" => 5,\n\t\t\t\t\"juni\" => 6,\n\t\t\t\t\"juli\" => 7,\n\t\t\t\t\"august\" => 8,\n\t\t\t\t\"september\" => 9,\n\t\t\t\t\"oktober\" => 10,\n\t\t\t\t\"november\" => 11,\n\t\t\t\t\"december\" => 12\n\t\t\t));\n\t\t\t\n\t\t\tif (preg_match(\"/(\\d+) (\\d+) (\\d+) (\\d+):(\\d+):(\\d+)/\", $date, $match)){\n\t\t\t\t$unixt = mktime($match[4], $match[5], $match[6], $match[2], $match[1], $match[3]);\n\t\t\t}elseif(preg_match(\"/(\\d+) ([a-z]{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2})/\", $date, $match)){\n\t\t\t\t$month = $match[2];\n\t\t\t\tif ($month == \"jan\"){\n\t\t\t\t\t$month_no = 1;\n\t\t\t\t}elseif($month == \"feb\"){\n\t\t\t\t\t$month_no = 2;\n\t\t\t\t}elseif($month == \"mar\"){\n\t\t\t\t\t$month_no = 3;\n\t\t\t\t}elseif($month == \"apr\"){\n\t\t\t\t\t$month_no = 4;\n\t\t\t\t}elseif($month == \"maj\"){\n\t\t\t\t\t$month_no = 5;\n\t\t\t\t}elseif($month == \"jun\"){\n\t\t\t\t\t$month_no = 6;\n\t\t\t\t}elseif($month == \"jul\"){\n\t\t\t\t\t$month_no = 7;\n\t\t\t\t}elseif($month == \"aug\"){\n\t\t\t\t\t$month_no = 8;\n\t\t\t\t}elseif($month == \"sep\"){\n\t\t\t\t\t$month_no = 9;\n\t\t\t\t}elseif($month == \"okt\"){\n\t\t\t\t\t$month_no = 10;\n\t\t\t\t}elseif($month == \"nov\"){\n\t\t\t\t\t$month_no = 11;\n\t\t\t\t}elseif($month == \"dec\"){\n\t\t\t\t\t$month_no = 12;\n\t\t\t\t}else{\n\t\t\t\t\tthrow new exception(\"Unknown month string: \" . $month);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t$unixt = mktime($match[4], $match[5], $match[6], $month_no, $match[1], $match[3]);\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Could not parse date: \" . $date);\n\t\t\t}\n\t\t\t\n\t\t\t$state = $matches[8][$key];\n\t\t\tif ($state == \"Gennemf\u00f8rt\"){\n\t\t\t\t$state = \"done\";\n\t\t\t}elseif(strpos($state, \"Gennemf\u00f8r\") !== false){\n\t\t\t\t$state = \"waiting\";\n\t\t\t}elseif($state == \"Annulleret\"){\n\t\t\t\t$state = \"canceled\";\n\t\t\t}elseif($state == \"Refunderet\"){\n\t\t\t\t$state = \"returned\";\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Unknown state: \" . $state);\n\t\t\t}\n\t\t\t\n\t\t\tif ($this->payments[$id]){\n\t\t\t\t$payment = $this->payments[$id];\n\t\t\t\t$payment->set(\"state\", $state);\n\t\t\t}else{\n\t\t\t\t$payment = new wfpayment_payment($this, array(\n\t\t\t\t\t\"id\" => $id,\n\t\t\t\t\t\"order_id\" => substr($matches[4][$key], 4),\n\t\t\t\t\t\"customer_id\" => $matches[3][$key],\n\t\t\t\t\t\"customer_string\" => $matches[4][$key],\n\t\t\t\t\t\"date\" => $unixt,\n\t\t\t\t\t\"amount\" => $amount,\n\t\t\t\t\t\"card_type\" => $card_type,\n\t\t\t\t\t\"state\" => $state\n\t\t\t\t));\n\t\t\t}\n\t\t\t\n\t\t\t$payments[] = $payment;\n\t\t}\n\t\t\n\t\treturn $payments;\n\t}\n}\n\nclass wfpayment_payment{\n\tfunction __construct($wfpayment, $args){\n\t\t$this->wfpayment = $wfpayment;\n\t\t$this->http = $this->wfpayment->http();\n\t\t$this->args = $args;\n\t}\n\t\n\tfunction set($key, $value){\n\t\t$this->args[$key] = $value;\n\t}\n\t\n\tfunction get($key){\n\t\tif (!array_key_exists($key, $this->args)){\n\t\t\tthrow new exception(\"No such key: \" . $key);\n\t\t}\n\t\t\n\t\treturn $this->args[$key];\n\t}\n\t\n\tfunction args(){\n\t\treturn $this->args;\n\t}\n\t\n\tfunction accept(){\n\t\tif ($this->state() == \"done\"){\n\t\t\tthrow new exception(\"This payment is already accepted.\");\n\t\t}\n\t\t\n\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactions.php?capture=singlecapture&transid=\" . $this->get(\"id\") . \"&page=1&orderby=&direction=\");\n\t\t\n\t\tif ($this->state() != \"done\"){\n\t\t\tthrow new exception(\"Could not accept the payment. State: \" . $this->state());\n\t\t}\n\t}\n\t\n\tfunction cancel(){\n\t\tif ($this->state() != \"waiting\"){\n\t\t\tthrow new exception(\"This is not waiting and cannot be canceled.\");\n\t\t}\n\t\t\n\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactionview.php?action=cancel&id=\" . $this->get(\"id\") . \"&page=1\");\n\t\t\n\t\tif ($this->state() != \"canceled\"){\n\t\t\tthrow new exception(\"Could not cancel the payment.\");\n\t\t}\n\t}\n\t\n\tfunction state(){\n\t\t$payments = $this->wfpayment->listPayments(array(\"order_id\" => $this->get(\"order_id\")));\n\t\tif (!$payments or !$payments[0]){\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn $payments[0]->get(\"state\");\n\t}\n}", "strings.php": " $value){\n\t\t\t\t$array[] = $value;\n\t\t\t\t$string = str_replace($matches[0][$key], \"\", $string);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (strlen($string) > 0){\n\t\t\tforeach(preg_split(\"/\\s/\", $string) AS $value){\n\t\t\t\tif (strlen(trim($value)) > 0){\n\t\t\t\t\t$array[] = $value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn $array;\n\t}\n\t\n\tstatic function parseImageHTML($content){\n\t\tif (preg_match_all(\"//U\", $content, $matches)){\n\t\t\tforeach($matches[0] AS $key => $value){\n\t\t\t\t$img_html = $value;\n\t\t\t\t\n\t\t\t\tif (preg_match(\"/src=\\\"([\\s\\S]+)\\\"/U\", $img_html, $match_src)){\n\t\t\t\t\t$src = $match_src[1];\n\t\t\t\t\tif (substr($src, 0, 1) == \"/\"){\n\t\t\t\t\t\t$src = substr($src, 1);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t$replace_with = \"image.php?picture=\" . $src;\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match(\"/width: ([0-9]+)(px|)/\", $img_html, $match_width)){\n\t\t\t\t\t\t$size[\"width\"] = $match_width[1];\n\t\t\t\t\t\t$replace_with .= \"&width=\" . $match_width[1];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match(\"/height: ([0-9]+)(px|)/\", $img_html, $match_height)){\n\t\t\t\t\t\t$size[\"height\"] = $match_height[1];\n\t\t\t\t\t\t$replace_with .= \"&height=\" . $match_width[1];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match_all(\"/(width|height)=\\\"([0-9]+)(px|)\\\"/\", $img_html, $match_sizes)){\n\t\t\t\t\t\t$size = array();\n\t\t\t\t\t\tforeach($match_sizes[1] AS $key => $sizetype){\n\t\t\t\t\t\t\tif (!$size[$sizetype]){\n\t\t\t\t\t\t\t\t$size[$sizetype] = $match_sizes[2][$key];\n\t\t\t\t\t\t\t\t$replace_with .= \"&\" . $sizetype . \"=\" . $match_sizes[2][$key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif ($size){\n\t\t\t\t\t\t$img_html = str_replace($src, $replace_with, $img_html);\n\t\t\t\t\t\t$content = str_replace($value, $img_html, $content);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn $content;\n\t}\n\t\n\tstatic function UnixSafe($string){\n\t\t$string = str_replace(\"\\\\\", \"\\\\\\\\\", $string);\n\t\t$string = str_replace(\" \", \"\\\\ \", $string);\n\t\t$string = str_replace(\"\\$\", \"\\\\\\$\", $string);\n\t\t$string = str_replace(\"(\", \"\\\\(\", $string);\n\t\t$string = str_replace(\")\", \"\\\\)\", $string);\n\t\t$string = str_replace(\";\", \"\\\\;\", $string);\n\t\t$string = str_replace(\",\", \"\\\\,\", $string);\n\t\t$string = str_replace(\"'\", \"\\\\'\", $string);\n\t\t$string = str_replace(\">\", \"\\\\>\", $string);\n\t\t$string = str_replace(\"<\", \"\\\\<\", $string);\n\t\t$string = str_replace(\"\\\"\", \"\\\\\\\"\", $string);\n\t\t$string = str_replace(\"&\", \"\\\\&\", $string);\n\t\t\n\t\t//Replace the end & - if any.\n\t\t//$string = preg_replace(\"/&\\s*$/\", \"\\\\&\", $string);\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function RegexSafe($string){\n\t\treturn strtr($string, array(\n\t\t\t\"/\" => \"\\\\/\",\n\t\t\t\".\" => \"\\\\.\",\n\t\t\t\"(\" => \"\\\\(\",\n\t\t\t\")\" => \"\\\\)\",\n\t\t\t\"[\" => \"\\\\[\",\n\t\t\t\"]\" => \"\\\\]\",\n\t\t\t\"^\" => \"\\\\^\",\n\t\t\t\"\\$\" => \"\\\\\\$\",\n\t\t\t\"+\" => \"\\\\+\"\n\t\t));\n\t}\n\t\n\tstatic function HeaderSafe($string){\n\t\treturn strtr($string, array(\n\t\t\t\"\\r\" => \"\",\n\t\t\t\"\\n\" => \" \"\n\t\t));\n\t}\n\t\n\tstatic function csvsafe($string){\n\t\t$string = htmlspecialchars($string);\n\t\t$string = str_replace(\"\\\"\", \"\", $string);\n\t\t$string = str_replace(\""\", \"\", $string);\n\t\t$string = str_replace(\"&\", \"&\", $string);\n\t\t$string = str_replace(\"\\r\", \"\", $string);\n\t\t$string = str_replace(\"\\n\", \"\", $string);\n\t\t$string = str_replace(\"<\", \"<\", $string);\n\t\t$string = str_replace(\">\", \">\", $string);\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function htmlspecialchars_textarea($text){\n\t\treturn preg_replace(\"/<\\/textarea>/i\", \"</textarea>\", $text);\n\t}\n\t\n\tstatic function jsparse($string, $paras = array()){\n\t\t$string = strtr($string, array(\n\t\t\t\"'\" => \"\\\\'\",\n\t\t\t\"\\\"\" => \""\",\n\t\t\t\"\\r\" => \"\",\n\t\t\t\"\\n\" => \"\\\\n\"\n\t\t));\n\t\t\n\t\tif ($paras[\"parse_quotes\"]){\n\t\t\t$string = str_replace(\"\\\"\", \"\\\\\\\"\", $string);\n\t\t}\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function tf_str($value, $yesstr, $nostr){\n\t\tif ($value){\n\t\t\treturn $yesstr;\n\t\t}\n\t\t\n\t\treturn $nostr;\n\t}\n\t\n\tstatic function shorten($text, $maxlength = nil){\n\t\tif (!$maxlength or strlen($text) <= $maxlength){\n\t\t\treturn $text;\n\t\t}\n\t\t\n\t\treturn trim(substr($text, 0, $maxlength)) . \"...\";\n\t}\n\t\n\tstatic function is_email($str){\n\t\tif (preg_match(\"/^(.+)@(.+)\\.(.+)/\", $str)){\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n}\n\n/**\n\t* Parses the quotes of a string.\n\t* \n\t* FIXME: DONT USE THIS FUNCTION! It will be removed soon... Look in the SQL-functions instead.\n*/\nfunction parse_quotes($string){\n\t$string = str_replace(\"'\", \"\\\\'\", $string);\n\t\n\tif (substr($string, -1, 1) == \"\\\\\" && substr($string, -2, 2) !== \"\\\\\\\\\"){\n\t\t$string = substr($string, 0, -1) . \"\\\\\\\\\";\n\t}\n\t\n\treturn $string;\n}\n\n/** Parse a string so it fits into the command-line of Linux. */\nfunction knj_string_unix_safe($string){\n\treturn knj_strings::UnixSafe($string);\n}\n\n/** Parse a string so it will be a valid filename. */\nfunction knj_string_filename($string, $os = null){\n\tif (!$os){\n\t\trequire_once(\"knj/os.php\");\n\t\t$os = knj_os::getOS();\n\t\t$os = $os[\"os\"];\n\t}\n\t\n\tif ($os == \"windows\"){\n\t\t//parse windows-filename here.\n\t}elseif($os == \"linux\"){\n\t\t$string = strtr($string, array(\n\t\t\t\"\u00e5\" => \"aa\",\n\t\t\t\"\u00f8\" => \"oe\",\n\t\t\t\"\u00e6\" => \"ae\",\n\t\t\tutf8_decode(\"\u00e5\") => \"aa\",\n\t\t\tutf8_decode(\"\u00e6\") => \"ae\",\n\t\t\tutf8_decode(\"\u00f8\") => \"oe\",\n\t\t\t\"|\" => \"\",\n\t\t\t\"&\" => \"\",\n\t\t\t\"/\" => \"\",\n\t\t\t\"\\\\\" => \"\"\n\t\t));\n\t}else{\n\t\tthrow new Exception(\"Unsupported OS.\");\n\t}\n\t\n\treturn $string;\n}\n\n/** Parse a string to it is safe in a regex-command. */\nfunction knj_string_regex($string){\n\treturn knj_strings::RegexSafe($string);\n}", "epay.php": "args = $args;\n\t\t\n\t\tif (!$this->args[\"username\"]){\n\t\t\tthrow new exception(\"No username was given.\");\n\t\t}\n\t\t\n\t\tif (!$this->args[\"password\"]){\n\t\t\tthrow new exception(\"No password was given.\");\n\t\t}\n\t\t\n\t\t$this->soap_client = new SoapClient(\"https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL\", array(\n\t\t\t\"verify_peer\" => false,\n\t\t\t\"allow_self_signed\" => true\n\t\t));\n\t}\n\t\n\tfunction transactions($args = array()){\n\t\t$res = $this->soap_client->__soapCall(\"gettransactionlist\", array(\"parameters\" => array_merge($args, array(\n\t\t\t\"merchantnumber\" => $this->args[\"merchant_no\"]\n\t\t))));\n\t\t$ret = array();\n\t\t\n\t\tif (is_array($res->transactionInformationAry->TransactionInformationType)){\n\t\t\tforeach($res->transactionInformationAry->TransactionInformationType as $trans_obj){\n\t\t\t\t$ret[] = new epay_payment(array(\n\t\t\t\t\t\"epay\" => $this,\n\t\t\t\t\t\"obj\" => $trans_obj,\n\t\t\t\t\t\"soap_client\" => $this->soap_client\n\t\t\t\t));\n\t\t\t}\n\t\t}elseif($res->transactionInformationAry->TransactionInformationType){\n\t\t\t$ret[] = new epay_payment(array(\n\t\t\t\t\"epay\" => $this,\n\t\t\t\t\"obj\" => $res->transactionInformationAry->TransactionInformationType,\n\t\t\t\t\"soap_client\" => $this->soap_client\n\t\t\t));\n\t\t}\n\t\t\n\t\treturn $ret;\n\t}\n\t\n\tfunction transaction($args = array()){\n\t\t$res = $this->soap_client->__soapCall(\"gettransaction\", array(\"parameters\" => array_merge($args, array(\n\t\t\t\"merchantnumber\" => $this->args[\"merchant_no\"],\n\t\t\t\"epayresponse\" => true\n\t\t))));\n\t\t\n\t\treturn new epay_payment(array(\n\t\t\t\"epay\" => $this,\n\t\t\t\"obj\" => $res->transactionInformation,\n\t\t\t\"soap_client\" => $this->soap_client\n\t\t));\n\t}\n}\n\nclass epay_payment{\n\tfunction __construct($args){\n\t\t$this->args = $args;\n\t\t$this->soap_client = $args[\"soap_client\"];\n\t\t\n\t\t$this->data = array(\n\t\t\t\"amount\" => floatval($args[\"obj\"]->authamount),\n\t\t\t\"orderid\" => intval($args[\"obj\"]->orderid),\n\t\t\t\"status\" => $args[\"obj\"]->status,\n\t\t\t\"transactionid\" => $args[\"obj\"]->transactionid\n\t\t);\n\t}\n\t\n\tfunction get($key){\n\t\tif ($key == \"id\"){\n\t\t\t$key = \"transactionid\";\n\t\t}\n\t\t\n\t\tif (!array_key_exists($key, $this->data)){\n\t\t\tthrow new exception(\"No such key: \" . $key);\n\t\t}\n\t\t\n\t\treturn $this->data[$key];\n\t}\n\t\n\tfunction args(){\n\t\treturn $this->args;\n\t}\n\t\n\tfunction accept(){\n\t\tif ($this->data[\"status\"] == \"PAYMENT_CAPTURED\"){\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\t$res = $this->soap_client->__soapCall(\"capture\", array(\"parameters\" => array(\n\t\t\t\"merchantnumber\" => $this->args[\"epay\"]->args[\"merchant_no\"],\n\t\t\t\"transactionid\" => $this->data[\"transactionid\"],\n\t\t\t\"amount\" => $this->data[\"amount\"],\n\t\t\t\"epayresponse\" => true,\n\t\t\t\"pbsResponse\" => true\n\t\t)));\n\t\t\n\t\tif (!$res->captureResult){\n\t\t\tthrow new exception(\"Could not accept payment.\\n\\n\" . print_r($res, true));\n\t\t}\n\t}\n\t\n\tfunction delete(){\n\t\t$res = $this->soap_client->__soapCall(\"delete\", array(\"parameters\" => array(\n\t\t\t\"merchantnumber\" => $this->args[\"epay\"]->args[\"merchant_no\"],\n\t\t\t\"transactionid\" => $this->data[\"transactionid\"],\n\t\t\t\"epayresponse\" => true\n\t\t)));\n\t\t\n\t\tif (!$res->deleteResult){\n\t\t\tthrow new exception(\"Could not delete payment.\\n\\n\" . print_r($res, true));\n\t\t}\n\t}\n\t\n\tfunction state(){\n\t\tthrow new exception(\"stub!\");\n\t}\n}"}, "files_after": {"wfpayment.php": "args = $args;\n\t\t\n\t\tif (!$this->args[\"username\"]){\n\t\t\tthrow new exception(\"No username was given.\");\n\t\t}\n\t\t\n\t\tif (!$this->args[\"password\"]){\n\t\t\tthrow new exception(\"No password was given.\");\n\t\t}\n\t\t\n\t\trequire_once \"knj/http.php\";\n\t\t$this->http = new knj_httpbrowser();\n\t\t$this->http->connect(\"betaling.wannafind.dk\", 443);\n\t\t\n\t\t$html = $this->http->getaddr(\"index.php\");\n\t\t\n\t\t$html = $this->http->post(\"pg.loginauth.php\", array(\n\t\t\t\"username\" => $this->args[\"username\"],\n\t\t\t\"password\" => $this->args[\"password\"]\n\t\t));\n\t\t\n\t\tif (strpos($html, \"Brugernavn eller password, blev ikke godkendt.\") !== false){\n\t\t\tthrow new exception(\"Could not log in.\");\n\t\t}\n\t}\n\t\n\tfunction http(){\n\t\treturn $this->http;\n\t}\n\t\n\tfunction listPayments($args = array()){\n\t\tif ($args[\"awaiting\"]){\n\t\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactions.php\");\n\t\t}else{\n\t\t\t$sargs = array(\n\t\t\t\t\"searchtype\" => \"\",\n\t\t\t\t\"fromday\" => \"01\",\n\t\t\t\t\"frommonth\" => \"01\",\n\t\t\t\t\"fromyear\" => date(\"Y\"),\n\t\t\t\t\"today\" => \"31\",\n\t\t\t\t\"tomonth\" => \"12\",\n\t\t\t\t\"toyear\" => date(\"Y\"),\n\t\t\t\t\"transacknum\" => \"\"\n\t\t\t);\n\t\t\t\n\t\t\tif ($args[\"order_id\"]){\n\t\t\t\t$sargs[\"orderid\"] = $args[\"order_id\"];\n\t\t\t}\n\t\t\t\n\t\t\t$html = $this->http->post(\"pg.frontend/pg.search.php?search=doit\", $sargs);\n\t\t}\n\t\t\n\t\tif (!preg_match_all(\"/]+)>\\s*([\\s\\S]+)<\\/tr>/U\", $html, $matches_tr)){\n\t\t\treturn array();\n\t\t}\n\t\t\n\t\tif (count($matches_tr[2]) == 1 or strlen(trim($matches_tr[2][0])) <= 0){\n\t\t\treturn array();\n\t\t}\n\t\t\n\t\t$payments = array();\n\t\tforeach($matches_tr[0] AS $key => $value){\n\t\t\tif (!preg_match_all(\"/]+)>(.*)<\\/td>/U\", $value, $matches_td)){\n\t\t\t\tthrow new exception(\"Could not match TDs.\");\n\t\t\t}\n\t\t\t\n\t\t\tif (!preg_match(\"/id=(\\d+)/\", $matches_td[2][0], $match_id)){\n\t\t\t\tthrow new exception(\"Could not match ID.\");\n\t\t\t}\n\t\t\t\n\t\t\t$id = $match_id[1];\n\t\t\t\n\t\t\t$amount = str_replace(\" DKK\", \"\", $matches_td[2][3]);\n\t\t\t$amount = strtr($amount, array(\n\t\t\t\t\".\" => \"\",\n\t\t\t\t\",\" => \".\"\n\t\t\t));\n\t\t\t\n\t\t\t$card_type = $matches_td[2][6];\n\t\t\t\n\t\t\tif (strpos($card_type, \"dk.png\") !== false){\n\t\t\t\t$card_type = \"dk\";\n\t\t\t}elseif(strpos($card_type, \"visa-elec.png\") !== false){\n\t\t\t\t$card_type = \"visa_electron\";\n\t\t\t}elseif(strpos($card_type, \"mc.png\") !== false){\n\t\t\t\t$card_type = \"mastercard\";\n\t\t\t}elseif(strpos($card_type, \"visa.png\") !== false){\n\t\t\t\t$card_type = \"visa\";\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Unknown card-type image: \" . $card_type);\n\t\t\t}\n\t\t\t\n\t\t\t$date = strtr($matches_td[2][2], array(\n\t\t\t\t\"januar\" => 1,\n\t\t\t\t\"februar\" => 2,\n\t\t\t\t\"marts\" => 3,\n\t\t\t\t\"april\" => 4,\n\t\t\t\t\"maj\" => 5,\n\t\t\t\t\"juni\" => 6,\n\t\t\t\t\"juli\" => 7,\n\t\t\t\t\"august\" => 8,\n\t\t\t\t\"september\" => 9,\n\t\t\t\t\"oktober\" => 10,\n\t\t\t\t\"november\" => 11,\n\t\t\t\t\"december\" => 12\n\t\t\t));\n\t\t\t\n\t\t\tif (preg_match(\"/(\\d+) (\\d+) (\\d+) (\\d+):(\\d+):(\\d+)/\", $date, $match)){\n\t\t\t\t$unixt = mktime($match[4], $match[5], $match[6], $match[2], $match[1], $match[3]);\n\t\t\t}elseif(preg_match(\"/(\\d+) ([a-z]{3}) (\\d{4}) (\\d{2}):(\\d{2}):(\\d{2})/\", $date, $match)){\n\t\t\t\t$month = $match[2];\n\t\t\t\tif ($month == \"jan\"){\n\t\t\t\t\t$month_no = 1;\n\t\t\t\t}elseif($month == \"feb\"){\n\t\t\t\t\t$month_no = 2;\n\t\t\t\t}elseif($month == \"mar\"){\n\t\t\t\t\t$month_no = 3;\n\t\t\t\t}elseif($month == \"apr\"){\n\t\t\t\t\t$month_no = 4;\n\t\t\t\t}elseif($month == \"maj\"){\n\t\t\t\t\t$month_no = 5;\n\t\t\t\t}elseif($month == \"jun\"){\n\t\t\t\t\t$month_no = 6;\n\t\t\t\t}elseif($month == \"jul\"){\n\t\t\t\t\t$month_no = 7;\n\t\t\t\t}elseif($month == \"aug\"){\n\t\t\t\t\t$month_no = 8;\n\t\t\t\t}elseif($month == \"sep\"){\n\t\t\t\t\t$month_no = 9;\n\t\t\t\t}elseif($month == \"okt\"){\n\t\t\t\t\t$month_no = 10;\n\t\t\t\t}elseif($month == \"nov\"){\n\t\t\t\t\t$month_no = 11;\n\t\t\t\t}elseif($month == \"dec\"){\n\t\t\t\t\t$month_no = 12;\n\t\t\t\t}else{\n\t\t\t\t\tthrow new exception(\"Unknown month string: \" . $month);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\t$unixt = mktime($match[4], $match[5], $match[6], $month_no, $match[1], $match[3]);\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Could not parse date: \" . $date);\n\t\t\t}\n\t\t\t\n\t\t\t$state = $matches_td[2][7];\n\t\t\tif (strpos($state, \"Gennemf\u00f8rt\") !== false){\n\t\t\t\t$state = \"done\";\n\t\t\t}elseif(strpos($state, \"Gennemf\u00f8r\") !== false){\n\t\t\t\t$state = \"waiting\";\n\t\t\t}elseif(strpos($state, \"Annulleret\") !== false){\n\t\t\t\t$state = \"canceled\";\n\t\t\t}elseif(strpos($state, \"Refunderet\") !== false){\n\t\t\t\t$state = \"returned\";\n\t\t\t}else{\n\t\t\t\tthrow new exception(\"Unknown state: \" . $state);\n\t\t\t}\n\t\t\t\n\t\t\tif ($this->payments[$id]){\n\t\t\t\t$payment = $this->payments[$id];\n\t\t\t\t$payment->set(\"state\", $state);\n\t\t\t}else{\n\t\t\t\t$payment = new wfpayment_payment($this, array(\n\t\t\t\t\t\"id\" => $id,\n\t\t\t\t\t\"order_id\" => substr($matches_td[2][1], 4),\n\t\t\t\t\t\"customer_id\" => $matches_td[2][1],\n\t\t\t\t\t\"customer_string\" => $matches_td[2][1],\n\t\t\t\t\t\"date\" => $unixt,\n\t\t\t\t\t\"amount\" => $amount,\n\t\t\t\t\t\"card_type\" => $card_type,\n\t\t\t\t\t\"state\" => $state\n\t\t\t\t));\n\t\t\t}\n\t\t\t\n\t\t\t$payments[] = $payment;\n\t\t}\n\t\t\n\t\treturn $payments;\n\t}\n}\n\nclass wfpayment_payment{\n\tfunction __construct($wfpayment, $args){\n\t\t$this->wfpayment = $wfpayment;\n\t\t$this->http = $this->wfpayment->http();\n\t\t$this->args = $args;\n\t}\n\t\n\tfunction set($key, $value){\n\t\t$this->args[$key] = $value;\n\t}\n\t\n\tfunction get($key){\n\t\tif (!array_key_exists($key, $this->args)){\n\t\t\tthrow new exception(\"No such key: \" . $key);\n\t\t}\n\t\t\n\t\treturn $this->args[$key];\n\t}\n\t\n\tfunction args(){\n\t\treturn $this->args;\n\t}\n\t\n\tfunction accept(){\n\t\tif ($this->state() == \"done\"){\n\t\t\tthrow new exception(\"This payment is already accepted.\");\n\t\t}\n\t\t\n\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactions.php?capture=singlecapture&transid=\" . $this->get(\"id\") . \"&page=1&orderby=&direction=\");\n\t\t\n\t\tif ($this->state() != \"done\"){\n\t\t\tthrow new exception(\"Could not accept the payment. State: \" . $this->state());\n\t\t}\n\t}\n\t\n\tfunction cancel(){\n\t\tif ($this->state() != \"waiting\"){\n\t\t\tthrow new exception(\"This is not waiting and cannot be canceled.\");\n\t\t}\n\t\t\n\t\t$html = $this->http->getaddr(\"pg.frontend/pg.transactionview.php?action=cancel&id=\" . $this->get(\"id\") . \"&page=1\");\n\t\t\n\t\tif ($this->state() != \"canceled\"){\n\t\t\tthrow new exception(\"Could not cancel the payment.\");\n\t\t}\n\t}\n\t\n\tfunction state(){\n\t\t$payments = $this->wfpayment->listPayments(array(\"order_id\" => $this->get(\"order_id\")));\n\t\tif (!$payments or !$payments[0]){\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\treturn $payments[0]->get(\"state\");\n\t}\n}", "strings.php": " $value){\n\t\t\t\t$string[$key] = knj_strings::utf8force($value);\n\t\t\t}\n\t\t\t\n\t\t\treturn $string;\n\t\t}else{\n\t\t\t$values = array();\n\t\t\t$special = array(\"\u00f8\", \"\u00e6\", \"\u00e5\", \"\u00d8\", \"\u00c6\", \"\u00c5\");\n\t\t\tforeach($special AS $value){\n\t\t\t\t$values[utf8_decode($value)] = $value;\n\t\t\t}\n\t\t\t\n\t\t\t$string = str_replace(\"\u00c3\u00a6\", \"\u00e6\", $string);\n\t\t\t\n\t\t\treturn strtr($string, $values);\n\t\t}\n\t}\n\t\n\t/** Parses a string into an array of strings, which should all be searched for. */\n\tstatic function searchstring($string){\n\t\t$array = array();\n\t\t\n\t\tif (preg_match_all(\"/\\\"(.*)\\\"/U\", $string, $matches)){\n\t\t\tforeach($matches[1] AS $key => $value){\n\t\t\t\t$array[] = $value;\n\t\t\t\t$string = str_replace($matches[0][$key], \"\", $string);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (strlen($string) > 0){\n\t\t\tforeach(preg_split(\"/\\s/\", $string) AS $value){\n\t\t\t\tif (strlen(trim($value)) > 0){\n\t\t\t\t\t$array[] = $value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn $array;\n\t}\n\t\n\tstatic function parseImageHTML($content){\n\t\tif (preg_match_all(\"//U\", $content, $matches)){\n\t\t\tforeach($matches[0] AS $key => $value){\n\t\t\t\t$img_html = $value;\n\t\t\t\t\n\t\t\t\tif (preg_match(\"/src=\\\"([\\s\\S]+)\\\"/U\", $img_html, $match_src)){\n\t\t\t\t\t$src = $match_src[1];\n\t\t\t\t\tif (substr($src, 0, 1) == \"/\"){\n\t\t\t\t\t\t$src = substr($src, 1);\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\t$replace_with = \"image.php?picture=\" . $src;\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match(\"/width: ([0-9]+)(px|)/\", $img_html, $match_width)){\n\t\t\t\t\t\t$size[\"width\"] = $match_width[1];\n\t\t\t\t\t\t$replace_with .= \"&width=\" . $match_width[1];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match(\"/height: ([0-9]+)(px|)/\", $img_html, $match_height)){\n\t\t\t\t\t\t$size[\"height\"] = $match_height[1];\n\t\t\t\t\t\t$replace_with .= \"&height=\" . $match_width[1];\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif (preg_match_all(\"/(width|height)=\\\"([0-9]+)(px|)\\\"/\", $img_html, $match_sizes)){\n\t\t\t\t\t\t$size = array();\n\t\t\t\t\t\tforeach($match_sizes[1] AS $key => $sizetype){\n\t\t\t\t\t\t\tif (!$size[$sizetype]){\n\t\t\t\t\t\t\t\t$size[$sizetype] = $match_sizes[2][$key];\n\t\t\t\t\t\t\t\t$replace_with .= \"&\" . $sizetype . \"=\" . $match_sizes[2][$key];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tif ($size){\n\t\t\t\t\t\t$img_html = str_replace($src, $replace_with, $img_html);\n\t\t\t\t\t\t$content = str_replace($value, $img_html, $content);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn $content;\n\t}\n\t\n\tstatic function UnixSafe($string){\n\t\t$string = str_replace(\"\\\\\", \"\\\\\\\\\", $string);\n\t\t$string = str_replace(\" \", \"\\\\ \", $string);\n\t\t$string = str_replace(\"\\$\", \"\\\\\\$\", $string);\n\t\t$string = str_replace(\"(\", \"\\\\(\", $string);\n\t\t$string = str_replace(\")\", \"\\\\)\", $string);\n\t\t$string = str_replace(\";\", \"\\\\;\", $string);\n\t\t$string = str_replace(\",\", \"\\\\,\", $string);\n\t\t$string = str_replace(\"'\", \"\\\\'\", $string);\n\t\t$string = str_replace(\">\", \"\\\\>\", $string);\n\t\t$string = str_replace(\"<\", \"\\\\<\", $string);\n\t\t$string = str_replace(\"\\\"\", \"\\\\\\\"\", $string);\n\t\t$string = str_replace(\"&\", \"\\\\&\", $string);\n\t\t\n\t\t//Replace the end & - if any.\n\t\t//$string = preg_replace(\"/&\\s*$/\", \"\\\\&\", $string);\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function RegexSafe($string){\n\t\treturn strtr($string, array(\n\t\t\t\"/\" => \"\\\\/\",\n\t\t\t\".\" => \"\\\\.\",\n\t\t\t\"(\" => \"\\\\(\",\n\t\t\t\")\" => \"\\\\)\",\n\t\t\t\"[\" => \"\\\\[\",\n\t\t\t\"]\" => \"\\\\]\",\n\t\t\t\"^\" => \"\\\\^\",\n\t\t\t\"\\$\" => \"\\\\\\$\",\n\t\t\t\"+\" => \"\\\\+\"\n\t\t));\n\t}\n\t\n\tstatic function HeaderSafe($string){\n\t\treturn strtr($string, array(\n\t\t\t\"\\r\" => \"\",\n\t\t\t\"\\n\" => \" \"\n\t\t));\n\t}\n\t\n\tstatic function csvsafe($string){\n\t\t$string = htmlspecialchars($string);\n\t\t$string = str_replace(\"\\\"\", \"\", $string);\n\t\t$string = str_replace(\""\", \"\", $string);\n\t\t$string = str_replace(\"&\", \"&\", $string);\n\t\t$string = str_replace(\"\\r\", \"\", $string);\n\t\t$string = str_replace(\"\\n\", \"\", $string);\n\t\t$string = str_replace(\"<\", \"<\", $string);\n\t\t$string = str_replace(\">\", \">\", $string);\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function htmlspecialchars_textarea($text){\n\t\treturn preg_replace(\"/<\\/textarea>/i\", \"</textarea>\", $text);\n\t}\n\t\n\tstatic function jsparse($string, $paras = array()){\n\t\t$string = strtr($string, array(\n\t\t\t\"'\" => \"\\\\'\",\n\t\t\t\"\\\"\" => \""\",\n\t\t\t\"\\r\" => \"\",\n\t\t\t\"\\n\" => \"\\\\n\"\n\t\t));\n\t\t\n\t\tif ($paras[\"parse_quotes\"]){\n\t\t\t$string = str_replace(\"\\\"\", \"\\\\\\\"\", $string);\n\t\t}\n\t\t\n\t\treturn $string;\n\t}\n\t\n\tstatic function tf_str($value, $yesstr, $nostr){\n\t\tif ($value){\n\t\t\treturn $yesstr;\n\t\t}\n\t\t\n\t\treturn $nostr;\n\t}\n\t\n\tstatic function shorten($text, $maxlength = nil){\n\t\tif (!$maxlength or strlen($text) <= $maxlength){\n\t\t\treturn $text;\n\t\t}\n\t\t\n\t\treturn trim(substr($text, 0, $maxlength)) . \"...\";\n\t}\n\t\n\tstatic function is_email($str){\n\t\tif (preg_match(\"/^(.+)@(.+)\\.(.+)/\", $str)){\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t}\n}\n\n/**\n\t* Parses the quotes of a string.\n\t* \n\t* FIXME: DONT USE THIS FUNCTION! It will be removed soon... Look in the SQL-functions instead.\n*/\nfunction parse_quotes($string){\n\t$string = str_replace(\"'\", \"\\\\'\", $string);\n\t\n\tif (substr($string, -1, 1) == \"\\\\\" && substr($string, -2, 2) !== \"\\\\\\\\\"){\n\t\t$string = substr($string, 0, -1) . \"\\\\\\\\\";\n\t}\n\t\n\treturn $string;\n}\n\n/** Parse a string so it fits into the command-line of Linux. */\nfunction knj_string_unix_safe($string){\n\treturn knj_strings::UnixSafe($string);\n}\n\n/** Parse a string so it will be a valid filename. */\nfunction knj_string_filename($string, $os = null){\n\tif (!$os){\n\t\trequire_once(\"knj/os.php\");\n\t\t$os = knj_os::getOS();\n\t\t$os = $os[\"os\"];\n\t}\n\t\n\tif ($os == \"windows\"){\n\t\t//parse windows-filename here.\n\t}elseif($os == \"linux\"){\n\t\t$string = strtr($string, array(\n\t\t\t\"\u00e5\" => \"aa\",\n\t\t\t\"\u00f8\" => \"oe\",\n\t\t\t\"\u00e6\" => \"ae\",\n\t\t\tutf8_decode(\"\u00e5\") => \"aa\",\n\t\t\tutf8_decode(\"\u00e6\") => \"ae\",\n\t\t\tutf8_decode(\"\u00f8\") => \"oe\",\n\t\t\t\"|\" => \"\",\n\t\t\t\"&\" => \"\",\n\t\t\t\"/\" => \"\",\n\t\t\t\"\\\\\" => \"\"\n\t\t));\n\t}else{\n\t\tthrow new Exception(\"Unsupported OS.\");\n\t}\n\t\n\treturn $string;\n}\n\n/** Parse a string to it is safe in a regex-command. */\nfunction knj_string_regex($string){\n\treturn knj_strings::RegexSafe($string);\n}", "epay.php": "args = $args;\n\t\t\n\t\tif (!$this->args[\"username\"]){\n\t\t\tthrow new exception(\"No username was given.\");\n\t\t}\n\t\t\n\t\tif (!$this->args[\"password\"]){\n\t\t\tthrow new exception(\"No password was given.\");\n\t\t}\n\t\t\n\t\t$this->soap_client = new SoapClient(\"https://ssl.ditonlinebetalingssystem.dk/remote/payment.asmx?WSDL\", array(\n\t\t\t\"verify_peer\" => false,\n\t\t\t\"allow_self_signed\" => true\n\t\t));\n\t}\n\t\n\tfunction transactions($args = array()){\n\t\t$res = $this->soap_client->__soapCall(\"gettransactionlist\", array(\"parameters\" => array_merge($args, array(\n\t\t\t\"merchantnumber\" => $this->args[\"merchant_no\"]\n\t\t))));\n\t\t$ret = array();\n\t\t\n\t\tif (is_array($res->transactionInformationAry->TransactionInformationType)){\n\t\t\tforeach($res->transactionInformationAry->TransactionInformationType as $trans_obj){\n\t\t\t\t$ret[] = new epay_payment(array(\n\t\t\t\t\t\"epay\" => $this,\n\t\t\t\t\t\"obj\" => $trans_obj,\n\t\t\t\t\t\"soap_client\" => $this->soap_client\n\t\t\t\t));\n\t\t\t}\n\t\t}elseif($res->transactionInformationAry->TransactionInformationType){\n\t\t\t$ret[] = new epay_payment(array(\n\t\t\t\t\"epay\" => $this,\n\t\t\t\t\"obj\" => $res->transactionInformationAry->TransactionInformationType,\n\t\t\t\t\"soap_client\" => $this->soap_client\n\t\t\t));\n\t\t}\n\t\t\n\t\treturn $ret;\n\t}\n\t\n\tfunction transaction($args = array()){\n\t\t$res = $this->soap_client->__soapCall(\"gettransaction\", array(\"parameters\" => array_merge($args, array(\n\t\t\t\"merchantnumber\" => $this->args[\"merchant_no\"],\n\t\t\t\"epayresponse\" => true\n\t\t))));\n\t\t\n\t\treturn new epay_payment(array(\n\t\t\t\"epay\" => $this,\n\t\t\t\"obj\" => $res->transactionInformation,\n\t\t\t\"soap_client\" => $this->soap_client\n\t\t));\n\t}\n}\n\nclass epay_payment{\n\tfunction __construct($args){\n\t\t$this->args = $args;\n\t\t$this->soap_client = $args[\"soap_client\"];\n\t\t\n\t\tif ($args[\"obj\"]->capturedamount){\n\t\t\t$amount = floatval($args[\"obj\"]->capturedamount);\n\t\t}else{\n\t\t\t$amount = floatval($args[\"obj\"]->authamount);\n\t\t}\n\t\t\n\t\t$this->data = array(\n\t\t\t\"amount\" => $amount,\n\t\t\t\"orderid\" => intval($args[\"obj\"]->orderid),\n\t\t\t\"status\" => $args[\"obj\"]->status,\n\t\t\t\"transactionid\" => $args[\"obj\"]->transactionid\n\t\t);\n\t}\n\t\n\tfunction get($key){\n\t\tif ($key == \"id\"){\n\t\t\t$key = \"transactionid\";\n\t\t}\n\t\t\n\t\tif (!array_key_exists($key, $this->data)){\n\t\t\tthrow new exception(\"No such key: \" . $key);\n\t\t}\n\t\t\n\t\treturn $this->data[$key];\n\t}\n\t\n\tfunction args(){\n\t\treturn $this->args;\n\t}\n\t\n\tfunction accept(){\n\t\tif ($this->data[\"status\"] == \"PAYMENT_CAPTURED\"){\n\t\t\treturn false;\n\t\t}\n\t\t\n\t\t$res = $this->soap_client->__soapCall(\"capture\", array(\"parameters\" => array(\n\t\t\t\"merchantnumber\" => $this->args[\"epay\"]->args[\"merchant_no\"],\n\t\t\t\"transactionid\" => $this->data[\"transactionid\"],\n\t\t\t\"amount\" => $this->data[\"amount\"],\n\t\t\t\"epayresponse\" => true,\n\t\t\t\"pbsResponse\" => true\n\t\t)));\n\t\t\n\t\tif (!$res->captureResult){\n\t\t\tthrow new exception(\"Could not accept payment.\\n\\n\" . print_r($res, true));\n\t\t}\n\t}\n\t\n\tfunction delete(){\n\t\t$res = $this->soap_client->__soapCall(\"delete\", array(\"parameters\" => array(\n\t\t\t\"merchantnumber\" => $this->args[\"epay\"]->args[\"merchant_no\"],\n\t\t\t\"transactionid\" => $this->data[\"transactionid\"],\n\t\t\t\"epayresponse\" => true\n\t\t)));\n\t\t\n\t\tif (!$res->deleteResult){\n\t\t\tthrow new exception(\"Could not delete payment.\\n\\n\" . print_r($res, true));\n\t\t}\n\t}\n\t\n\tfunction state(){\n\t\tthrow new exception(\"stub!\");\n\t}\n}"}} {"repo": "collective/collective.setuphandlertools", "pr_number": 1, "title": "Depend on Products.CMFPlone instead of Plone to not fetch unnecessary\u2026", "state": "closed", "merged_at": "2018-02-08T13:11:26Z", "additions": 8, "deletions": 1, "files_changed": ["setup.py"], "files_before": {"setup.py": "from setuptools import setup, find_packages\nimport os\n\nversion = '1.0b4'\n\nsetup(name='collective.setuphandlertools',\n version=version,\n description=\"Tools for setting up a Plone site.\",\n long_description=open(\"README.txt\").read() + \"\\n\\n\" +\n open(os.path.join(\"docs\", \"HISTORY.txt\")).read(),\n # Get more strings from http://pypi.python.org/pypi?:action=list_classifiers\n classifiers=[\n \"Framework :: Plone\",\n \"Programming Language :: Python\",\n ],\n keywords='plone zope setup',\n author='Johannes Raggam',\n author_email='raggam-nl@adm.at',\n url='http://github.com/collective/collective.setuphandlertools',\n license='GPL',\n packages=find_packages(exclude=['ez_setup']),\n namespace_packages=['collective'],\n include_package_data=True,\n zip_safe=False,\n install_requires=[\n 'setuptools',\n # -*- Extra requirements: -*-\n 'Plone',\n 'Products.ATContentTypes',\n 'Products.CMFCore',\n 'Products.PortalTransforms',\n ],\n )\n"}, "files_after": {"setup.py": "from setuptools import setup, find_packages\nimport os\n\nversion = '1.0b4'\n\nsetup(name='collective.setuphandlertools',\n version=version,\n description=\"Tools for setting up a Plone site.\",\n long_description=open(\"README.txt\").read() + \"\\n\\n\" +\n open(os.path.join(\"docs\", \"HISTORY.txt\")).read(),\n # Get more strings from http://pypi.python.org/pypi?:action=list_classifiers\n classifiers=[\n \"Framework :: Plone\",\n \"Programming Language :: Python\",\n ],\n keywords='plone zope setup',\n author='Johannes Raggam',\n author_email='raggam-nl@adm.at',\n url='http://github.com/collective/collective.setuphandlertools',\n license='GPL',\n packages=find_packages(exclude=['ez_setup']),\n namespace_packages=['collective'],\n include_package_data=True,\n zip_safe=False,\n install_requires=[\n 'setuptools',\n # -*- Extra requirements: -*-\n 'Products.CMFPlone',\n 'Products.ATContentTypes',\n 'Products.CMFCore',\n 'Products.PortalTransforms',\n ],\n )\n"}} {"repo": "balinterdi/balinterdi.github.com", "pr_number": 13, "title": "Sales web changes", "state": "closed", "merged_at": "2016-03-07T13:05:36Z", "additions": 13, "deletions": 1, "files_changed": ["source/_layouts/rarwe_book.html"], "files_before": {"source/_layouts/rarwe_book.html": "\n\n\n\n \n \n \n \n\n \n \n \n \n \n \n\n \n \n\n Cut your learning curve and build ambitious apps with Ember.js.\n\n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n\n\n
\n\n \n
\n
\n\n \n\n
\n
\n
\n \"Rock\n
\n
\n
\n
\n

Build ambitious apps with confidence

\n

Ember.js is a kick-ass framework for building\n web applications. It's the only tool you need\n (on the client-side) to craft your idea into a working\n wonder. However, its strong opinions and heavy reliance of\n \u201cconvention over configuration\u201d can give developers who\n are new to the framework a hard time figuring out how\n Ember wants them to do things.

\n\n

This book helps to overcome that initial\n frustration, and help you grok Ember a lot\n faster, by pinpointing the core concepts and\n explaining them in detail. Once you understand them you\n are on your way to taming and mastering Ember.js.\n So don't fear the learning curve.

\n\n
\n
\n
\n

This is a really great book. I think it will be very helpful to many people. I\u2019m definitely going to recommend it to beginners.

\n
\n
\n
\n \"Taras\n
\n
\n — Taras Mankowski\n EmberSherpa\n
\n
\n
\n
\n

The book guides you through the steps of building a real application so that you can see how the concepts are applied in practice. You'll learn about the building blocks of Ember one by one, in a way that crushes the steep learning curve. Knowledge is dripped in slowly, chapter by chapter, to prevent you from drowning in a sea of novel information. By improving an existing and working application, you will learn more quickly and new knowledge will sink in deeper.

\n

Already convinced? Skip to the packages.

\n
\n\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n \"Sample\n
\n
\n
\n
\n

Want to read a sample chapter first?

\n \n
\n\n
\n \n \n
\n \n \n
\n
\n

There was an error submitting your subscription. Please try again.

\n
\n
\n
\n \n \n
\n
\n \n \n
\n \n We won't send you spam. Unsubscribe at any time.\n
\n
\n
\n
\n\n
\n
\n
\n
\n \n \n \n\n \n
\n
\n
\n
\n \n
\n
\n

Once upon a time...

\n
\n
\n
\n\n
\n

\n It all started in September 2013. Having just returned from the first European\n Ember.js conference, my enthusiasm went through the roof. I wanted to spread the\n word, for people to realize how beautiful Ember is, for them to know\n that Ember.js is not that hard to learn. It's just a matter of having the core\n concepts internalized.\n

\n

\n So without proper equipment (and after a few episodes, with a ~$80 mic) I started producing screencasts, a series in\n which a simple application is developed step-by-step. I sent the first few to my\n subscribers and kept producing them. And people seemed to have liked them.\n

\n\n
\n
\n
\n
\n
\n

Great episode! Pace and depth was perfect. Thanks for such a great webcast series!

\n
\n
\n
\n \"Curtis\n
\n
\n — Curtis Wallen\n
\n
\n
\n
\n\n
\n
\n
\n

I really appreciate the effort you want to put up. Just wanted to thank you for this and let you know that your video series rock!

\n
\n
\n
\n \"Antonio\n
\n
\n — Antonio Antillon\n
\n
\n
\n
\n
\n
\n\n

\n Once the screencast series was finished, I switched to blog posts and lengthier\n articles, and in 2014 I committed to posting something of\n value each week. Then, after a long labor of (mostly) love,\n I published the 1st edition of the book in Feburary\n 2015, that used the then stable Ember version, 1.10.\n

\n

\n I was not done, though. As Ember made progress in a\n neck breaking pace, I kept the book up-to-date with the\n actual stable version of the framework, and adding material\n that covered the new features.\n

\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Buy once, get all updates for free

\n
\n
\n
\n\n
\n

The first edition of this book followed Ember's journey to\n its 2.0 release. As Ember gracefully shedded old syntaxes, the\n book's content was updated not to use those syntaxes, either.\n When a new feature appeared, I added a section about it, trying\n to find a practical example for it in the application.

\n\n

Since Ember follows a 6-week release cycle, that meant\n frequent book updates, precisely 8 \"minor book releases\" in a\n little less than 7 months. These updates came free for all of my\n customers, no matter which package they chose. I aim to follow a\n similar path and update policy with Ember 2.x. The framework\n makes progress really fast but I'll keep in sync with the latest\n stable version of Ember and keep the content fresh. And\n free until at least the next major version.

\n
\n
\n\n
\n
\n
\n
\n
\n

I really like it! It is super difficult to find the right balance between pacing and detail\nand put it all together in an understandable form but you pulled it off.

\n
\n
\n
\n \"Cory\n
\n
\n — Cory Forsyth\n 201 Created\n
\n
\n
\n
\n\n
\n
\n
\n

Just wanted to say thanks for the ongoing updates of the book. Even after finishing the book, it\u2019s becoming a great reference for the changes Ember is going through (even more so than the official docs).

\n
\n
\n
\n \"Gabriel\n
\n
\n — Gabriel Rotbart\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n
\n

Table of Contents

\n
\n
\n
\n
\n\n
\n
\n
\n \n
\n
    \n
  • Preface\n\n
      \n
    • My love affair with Ember.js
    • \n
    • Acknowledgements
    • \n
  • \n
  • Introduction to Ember.js\n\n
      \n
    • Why Ember.js
    • \n
    • Backstage - Dial M for Model
    • \n
    • About this book
    • \n
    • Is this book for you?
    • \n
    • Ambitious goal for an ambitious framework
    • \n
    • The application we are going to build
    • \n
    • Errata
    • \n
  • \n
  • Ember CLI\n\n
      \n
    • Setting up Ember CLI
    • \n
    • Creating our application
    • \n
  • \n
  • Templates and data bindings\n\n
      \n
    • The first template
    • \n
    • Showing a list of songs in the application template
    • \n
    • Backstage - Handlebar's fail-softness
    • \n
    • Backstage - ES2015 modules
    • \n
    • Backstage - Class and instance properties
    • \n
    • Adding libraries to the build
    • \n
    • Importing needed assets manually
    • \n
    • Using an Ember add-on
    • \n
    • Auto-updating templates
    • \n
  • \n
  • Routing\n\n
      \n
    • What do we want to achieve?
    • \n
    • New styles
    • \n
    • Routes set up data
    • \n
    • Backstage - A word about generated test files
    • \n
    • Moving around with link-to
    • \n
    • Using the model property
    • \n
    • Showing a list of bands
    • \n
    • Showing a list of songs
    • \n
  • \n
  • Nested routes\n\n
      \n
    • Defining the nested routes
    • \n
    • Full route names
    • \n
    • Backstage - Resource routes
    • \n
    • Stepping through a router transition
    • \n
    • Backstage - Computed properties
    • \n
    • Nested templates
    • \n
    • {{outlet}} is the default template for routes
    • \n
  • \n
  • Actions\n\n
      \n
    • Extracting model classes
    • \n
    • The class-level mutable attribute property
    • \n
    • Capturing the event
    • \n
    • Turning event into intent
    • \n
  • \n
  • Components\n\n
      \n
    • The idea behind components
    • \n
    • Component specification
    • \n
    • Defining the component's properties
    • \n
    • Using the component
    • \n
    • Displaying the rating with stars
    • \n
    • Backstage - The default component template
    • \n
    • Backstage - On the utility of explicit dependency definitions
    • \n
    • Speaking to the outside world through actions
    • \n
    • Closure actions
    • \n
  • \n
  • Controllers\n\n
      \n
    • Preventing the creation of bands without a name
    • \n
    • Smooth UI flows
    • \n
    • Going to the band page after it is created
    • \n
    • Nudging the user to create the first song
    • \n
    • Showing the text field when the call to action has been acted on
    • \n
    • Creating new bands and songs by pressing return
    • \n
    • Backstage - Where to handle actions?
    • \n
  • \n
  • Advanced routing\n\n
      \n
    • Route hooks
    • \n
    • Route actions
    • \n
    • Redirection
    • \n
    • Redirecting before the model is known
    • \n
    • Redirecting after the model is known
    • \n
    • Backstage - Skipping model resolution
    • \n
    • Leaving routes and arriving at them
    • \n
    • Setting descriptive page titles
    • \n
    • Warning about losing data
    • \n
  • \n
  • Talking to a backend - with Ember Data\n\n
      \n
    • The concept behind Ember Data
    • \n
    • The API
    • \n
    • Model classes
    • \n
    • Transforming the app to use Ember Data
    • \n
    • Loading bands
    • \n
    • Fetching a single band
    • \n
    • Loading songs for a band
    • \n
    • Creating a band
    • \n
    • Updating a band's description
    • \n
    • Updating song ratings
    • \n
    • Backstage - Promises
    • \n
  • \n
  • Testing\n\n
      \n
    • Clarifying the vocabulary
    • \n
    • Acceptance tests
    • \n
    • To mock or not to mock?
    • \n
    • Unit tests
    • \n
    • Integration tests
    • \n
    • Adding an acceptance test
    • \n
    • Analyzing an Ember acceptance test
    • \n
    • Making the first test pass
    • \n
    • Safeguarding critical user scenarios
    • \n
    • Creating a band
    • \n
    • Creating a song
    • \n
    • Backstage \u2013 Fake synchronous tests
    • \n
    • Writing your own test helpers
    • \n
    • Registering a synchronous helper
    • \n
    • Registering an async helper
    • \n
    • Refactoring stubs
    • \n
    • Integration tests in Ember
    • \n
    • Unit tests in Ember
    • \n
  • \n
  • Sorting and searching with query parameters\n\n
      \n
    • Query parameters
    • \n
    • Query parameters in Ember
    • \n
    • Sorting the list of songs
    • \n
    • Sorting an array of items
    • \n
    • Backstage - Computed property macros
    • \n
    • Changing the sorting criteria
    • \n
    • Filtering songs by a search term
    • \n
    • Adding a dash of query parameters
    • \n
    • Using links instead of buttons
    • \n
    • Taking a look at what we made
    • \n
  • \n
  • Loading and error routes\n\n
      \n
    • Loading routes
    • \n
    • Backstage - Rendering the loading template is an overridable default
    • \n
    • Error routes
    • \n
  • \n
  • Helpers\n\n
      \n
    • About helpers
    • \n
    • Capitalizing each word of a name
    • \n
    • Using it in templates, or elsewhere
    • \n
    • Use dashed names for helpers
    • \n
  • \n
  • Animations\n\n
      \n
    • Setting up liquid-fire
    • \n
    • liquid-fire architecture
    • \n
    • Transition map
    • \n
    • Transition functions
    • \n
    • Template helpers
    • \n
    • Putting it all together
    • \n
    • Debugging transitions
    • \n
    • Animate moving between routes
    • \n
    • Adding a custom animation
    • \n
    • Animate a value change
    • \n
  • \n
  • Making an Ember addon\n\n
      \n
    • What is an Ember addon?
    • \n
    • Developing the addon
    • \n
    • Integrating our addon into our app
    • \n
    • Adding a block form
    • \n
    • Customizing the star-rating component's look and behavior
    • \n
    • Publishing the addon
    • \n
    • Using a published addon from the app
    • \n
  • \n
  • ES2015 - Writing modern JavaScript\n\n
      \n
    • Modernizing the app
    • \n
    • Modules
    • \n
    • Template strings
    • \n
    • Short-hand method definitions
    • \n
    • Replacing var (let & const)
    • \n
    • Arrow functions
    • \n
    • Destructuring
    • \n
    • Other useful ES2015 features
    • \n
    • Backstage - ember-watson
    • \n
    • Computed property macros
    • \n
  • \n
  • Deployment\n\n
      \n
    • FrontPage
    • \n
    • Heroku
    • \n
    • ember-cli-deploy
    • \n
  • \n
  • Afterword\n\n
      \n
    • Your journey with Ember.js
    • \n
  • \n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \"Balint\n
\n\n
\n

About me

\n

Hello there, I'm Balint Erdi.

\n

\n I have a long history of building web applications and have mostly been a back-end\n guy.\n

\n

\n On a grey, chilly February day in 2013 that I\u2019ll never forget (maybe it was\n January?) I got acquainted with Ember.js. Ember.js made that day bright and the\n ones that came after that. After learning the ropes I shifted gears and have been\n proselytizing for Ember since last summer.\n

\n

\n I gave a beginner\u2019s workshop at Eurucamp, and held presentations at Arrrrcamp, The Geek Gathering and EmberFest. I started an Ember.js mailing list, made an introductory\n screencast series and have been sending Ember content to my dear subscribers on a\n weekly basis. I have also written guest articles for Safari Books Online, Firebase\n and Toptal.\n

\n

\n I guess you could say I\u2019m pretty passionate about Ember.\n

\n

\n Oh, and I love rock & roll, obviously.\n

\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Bonus: Exclusive hack.hands() deal

\n
\n
\n
\n
\n

\n hack.hands()\n is your SOS button for live programming support, available 24/7. hack.hands() instantly connects developers with a network of expert programmers at the click of a button. Never get stuck, learn more and keep coding!\n If you buy any package, you will receive $25 to spend on their platform that you can use to get your Ember project unstuck.\n

\n
\n
\n\n
\n
\n
\n
\n
\n

Even though I have worked with Ember for the past 6 months, the book helped clarify a lot of things, especially new features and their deprecated counterparts. Such a great book, and looking forward to the second one!

\n
\n
\n
\n \"David\n
\n
\n — David Tang\n
\n
\n
\n
\n\n
\n
\n
\n

There is almost nowhere to go to get a good grounding in Ember. In months of searching this is the best resource that exists... so much so I'm going to try to get a few copies sorted out for my team at work. Thanks Balint!

\n
\n
\n
\n \"\n
\n
\n — Andy Davison\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n

Stairway to Heaven Package

\n
\n
\n
\n\n
\n
\n

\n The path to Ember.js bliss, this package contains all you need to take your Ember.js skills to the next level. It contains:

\n \"Stairway\n

\n
\n
\n
\n\n
\n
\n
\n
\n
\n

This was a truly great series of screencasts. Very, very well done. Simple enough while not being simplistic.

\n
\n
\n
\n \"Claude\n
\n
\n — Claude Pr\u00e9court\n
\n
\n
\n
\n\n
\n
\n
\n

Nice work with these Ember tutorials. You're doing a really nice thing for the community.

\n
\n
\n
\n \"Steven\n
\n
\n — Steven Kane\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Code\"\n
\n

Access to the code

\n All of the source code\n

in the application so that you can check how the app looks & works at each step. Or tweak it to your liking.

\n
\n
\n\n
\n
\n
\n \"Screencast\"\n
\n

Screencasts

\n 4 screencasts\n

They run around 10 minutes each and cover the following,\n advanced topics: Pods in Ember CLI, Animations,\n Authentication & Authorization, and ES2015 &\n computed macros.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n
\n
\n\n
\n \n
\n\n
\n
\n\n \n
\n
\n
\n
\n
\n

Light my Fire Package

\n
\n
\n
\n\n
\n
\n

\n Take out the screencasts and you have this smaller package that will still ignite your Ember rocket. It contains:\n \"Light\n

\n
\n
\n
\n
\n\n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Code\"\n
\n

Access to the code

\n All of the source code\n

in the application so that you can check how the app looks & works at each step. Or tweak it to your liking.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n
\n
\n\n
\n \n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n

Smoke on the Water Package

\n
\n
\n
\n\n
\n
\n

\n Basic but still solid, as the name suggests. This package inclues the book and the hack.hands() deal. It contains:\n

\n \"Smoke\n

\n
\n
\n
\n
\n\n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n\n
\n
\n\n
\n \n
\n\n
\n
\n
\n
\n
\n

I\u2019m REALLY enjoying the book and find it to be very thorough and informative. You\u2019ve done a great job of answering questions I had about various concepts that were not detailed clearly elsewhere.

\n
\n
\n
\n \"Bill\n
\n
\n — Bill White\n Data Visualizations at www.bildwhite.com\n
\n
\n
\n
\n\n
\n
\n
\n

It\u2019s been an invaluable resource in learning Ember and one I would recommend to any developer wanting to get started with the framework.

\n
\n
\n
\n \"Jonathan\n
\n
\n — Jonathan Rowley\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Hmm, I\u2019m not sure...

\n
\n
\n
\n\n
\n
    \n
  • \n

    Is the book ready for Ember 2?

    \n

    \n Yes, it is! The app in the book runs Ember (and Ember Data)\n 2 and does not use any deprecated stuff.\n

    \n
  • \n\n
  • \n

    Is this book for me?

    \n

    \n The book starts from the very basics (installing\n ember-cli, writing your first template, etc.) so if you\n completely get Ember, this book is probably not for you. If\n you are just starting out (or about to) or want to\n understand fundamental concepts in Ember, the book is\n definitely for you.\n

    \n
  • \n\n
  • \n

    What if I don't like the book?

    \n

    \n I offer a 60-day moneyback guarantee. No strings attached,\n just send your purchase receipt (or email address) to\n rarwe-book@balinterdi.com or answer to the welcome email\n that you received when you purchased.\n

    \n
  • \n\n
  • \n

    Everything is changing so fast; won't the content be outdated by next week?

    \n

    \n As Ember.js moves towards 3.0, I will keep updating the\n content of the book so that it stays void of deprecation\n warnings and does not promote practices that are no longer\n considered idiomatic. For the 1st edition of the book,\n I released an update once about every four weeks,\n more often than Ember stable versions came out.\n Expect the same for the this book edition.\n

    \n
  • \n\n
  • \n

    I heard Ember is so hard. Will this book help me understand it?

    \n

    \n I think there are a handful of key concepts in Ember.js\n that you need to understand to master it (probably the main\n one among these is routing). Once you understand these,\n Ember is not that hard. The intention of the book is\n to introduce concepts by way of building an actual\n application, so you see them applied in practice right away.\n That also helps the learning process. I also encourage you\n to work through the book as you read it, since that makes\n things sink in even deeper. You have access to the code\n repository if you have purchased the middle- or\n high-tier package. If I failed to explain Ember for you, please\n send me your purchase receipt to rarwe-book@balinterdi.com\n within 60 days of purchase and I\u2019ll issue a refund.\n

    \n
  • \n\n
  • \n

    Is the book DRM protected?

    \n

    \n No, it\u2019s not. If you would like to share it with\n colleagues (or a class), please contact me at rarwe-book@balinterdi.com.

    \n
  • \n\n
  • \n

    What if I buy the book-only package and later realize I want to switch to a higher package?

    \n

    No problem! Just send me your purchase receipt to rarwe-book@balinterdi.com, and I will upgrade you for the difference between the package prices.

    \n
  • \n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n \"60-day\n
\n\n \n
\n
\n

Choose a Package

\n
\n
\n
\n
\n\n
\n
\n
    \n
  • \n

    Smoke on the Water

    \n
    \n
    \n $39\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    • \n
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
  • \n

    Light my Fire

    \n
    \n
    \n $59\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • Access to the code
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
  • \n

    Stairway to Heaven

    \n
    \n
    \n $89\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • Access to the code
    • \n
    • 4 Screencasts
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n\n
\n
\n

This book is a fabulous, approachable, foray into Emberjs that makes the learning curve much less scary. I just wish it had been available sooner for students in my previous classes.

\n
\n
\n
\n \"Matt\n
\n
\n — Matt Hale\n Assistant Professor at the University of Nebraska\n
\n
\n
\n
\n\n
\n
\n
\n

I\u2019ve gone through the first four chapters and I am already loving it.

\n
\n
\n
\n \"Sergio\n
\n
\n — Sergio Arbeo\n EmberMadrid\n
\n
\n
\n
\n
\n
\n
\n \n\n \n \n \n\n \n\n \n \n \n \n\n \n \n\n\n\n"}, "files_after": {"source/_layouts/rarwe_book.html": "\n\n\n\n \n \n \n \n\n \n \n \n \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n Cut your learning curve and build ambitious apps with Ember.js.\n\n \n \n \n \n \n \n \n \n \n\n \n \n \n \n \n\n\n\n
\n\n \n
\n
\n\n
\n
\n

The most up-to-date book to learn Ember.js

\n
\n Trusted by:\n \"Toptal\"\n \"Firebase\"\n \"Airpair\"\n \"Nathan\n
\n
\n
\n\n
\n
\n
\n \"Rock\n
\n
\n
\n
\n

Build ambitious apps with confidence

\n

Ember.js is a kick-ass framework for building\n web applications. It's the only tool you need\n (on the client-side) to craft your idea into a working\n wonder. However, its strong opinions and heavy reliance of\n \u201cconvention over configuration\u201d can give developers who\n are new to the framework a hard time figuring out how\n Ember wants them to do things.

\n\n

This book helps to overcome that initial\n frustration, and help you grok Ember a lot\n faster, by pinpointing the core concepts and\n explaining them in detail. Once you understand them you\n are on your way to taming and mastering Ember.js.\n So don't fear the learning curve.

\n\n
\n
\n
\n

This is a really great book. I think it will be very helpful to many people. I\u2019m definitely going to recommend it to beginners.

\n
\n
\n
\n \"Taras\n
\n
\n — Taras Mankowski\n EmberSherpa\n
\n
\n
\n
\n

The book guides you through the steps of building a real application so that you can see how the concepts are applied in practice. You'll learn about the building blocks of Ember one by one, in a way that crushes the steep learning curve. Knowledge is dripped in slowly, chapter by chapter, to prevent you from drowning in a sea of novel information. By improving an existing and working application, you will learn more quickly and new knowledge will sink in deeper.

\n

Already convinced? Skip to the packages.

\n
\n\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n \"Sample\n
\n
\n
\n
\n

Want to read a sample chapter first?

\n \n
\n\n
\n \n \n
\n \n \n
\n
\n

There was an error submitting your subscription. Please try again.

\n
\n
\n
\n \n \n
\n
\n \n \n
\n \n We won't send you spam. Unsubscribe at any time.\n
\n
\n
\n
\n\n
\n
\n
\n
\n \n \n \n\n \n
\n
\n
\n
\n \n
\n
\n

Once upon a time...

\n
\n
\n
\n\n
\n

\n It all started in September 2013. Having just returned from the first European\n Ember.js conference, my enthusiasm went through the roof. I wanted to spread the\n word, for people to realize how beautiful Ember is, for them to know\n that Ember.js is not that hard to learn. It's just a matter of having the core\n concepts internalized.\n

\n

\n So without proper equipment (and after a few episodes, with a ~$80 mic) I started producing screencasts, a series in\n which a simple application is developed step-by-step. I sent the first few to my\n subscribers and kept producing them. And people seemed to have liked them.\n

\n\n
\n
\n
\n
\n
\n

Great episode! Pace and depth was perfect. Thanks for such a great webcast series!

\n
\n
\n
\n \"Curtis\n
\n
\n — Curtis Wallen\n
\n
\n
\n
\n\n
\n
\n
\n

I really appreciate the effort you want to put up. Just wanted to thank you for this and let you know that your video series rock!

\n
\n
\n
\n \"Antonio\n
\n
\n — Antonio Antillon\n
\n
\n
\n
\n
\n
\n\n

\n Once the screencast series was finished, I switched to blog posts and lengthier\n articles, and in 2014 I committed to posting something of\n value each week. Then, after a long labor of (mostly) love,\n I published the 1st edition of the book in Feburary\n 2015, that used the then stable Ember version, 1.10.\n

\n

\n I was not done, though. As Ember made progress in a\n neck breaking pace, I kept the book up-to-date with the\n actual stable version of the framework, and adding material\n that covered the new features.\n

\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Buy once, get all updates for free

\n
\n
\n
\n\n
\n

The first edition of this book followed Ember's journey to\n its 2.0 release. As Ember gracefully shedded old syntaxes, the\n book's content was updated not to use those syntaxes, either.\n When a new feature appeared, I added a section about it, trying\n to find a practical example for it in the application.

\n\n

Since Ember follows a 6-week release cycle, that meant\n frequent book updates, precisely 8 \"minor book releases\" in a\n little less than 7 months. These updates came free for all of my\n customers, no matter which package they chose. I aim to follow a\n similar path and update policy with Ember 2.x. The framework\n makes progress really fast but I'll keep in sync with the latest\n stable version of Ember and keep the content fresh. And\n free until at least the next major version.

\n
\n
\n\n
\n
\n
\n
\n
\n

I really like it! It is super difficult to find the right balance between pacing and detail\nand put it all together in an understandable form but you pulled it off.

\n
\n
\n
\n \"Cory\n
\n
\n — Cory Forsyth\n 201 Created\n
\n
\n
\n
\n\n
\n
\n
\n

Just wanted to say thanks for the ongoing updates of the book. Even after finishing the book, it\u2019s becoming a great reference for the changes Ember is going through (even more so than the official docs).

\n
\n
\n
\n \"Gabriel\n
\n
\n — Gabriel Rotbart\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n
\n

Table of Contents

\n
\n
\n
\n
\n\n
\n
\n
\n \n
\n
    \n
  • Preface\n\n
      \n
    • My love affair with Ember.js
    • \n
    • Acknowledgements
    • \n
  • \n
  • Introduction to Ember.js\n\n
      \n
    • Why Ember.js
    • \n
    • Backstage - Dial M for Model
    • \n
    • About this book
    • \n
    • Is this book for you?
    • \n
    • Ambitious goal for an ambitious framework
    • \n
    • The application we are going to build
    • \n
    • Errata
    • \n
  • \n
  • Ember CLI\n\n
      \n
    • Setting up Ember CLI
    • \n
    • Creating our application
    • \n
  • \n
  • Templates and data bindings\n\n
      \n
    • The first template
    • \n
    • Showing a list of songs in the application template
    • \n
    • Backstage - Handlebar's fail-softness
    • \n
    • Backstage - ES2015 modules
    • \n
    • Backstage - Class and instance properties
    • \n
    • Adding libraries to the build
    • \n
    • Importing needed assets manually
    • \n
    • Using an Ember add-on
    • \n
    • Auto-updating templates
    • \n
  • \n
  • Routing\n\n
      \n
    • What do we want to achieve?
    • \n
    • New styles
    • \n
    • Routes set up data
    • \n
    • Backstage - A word about generated test files
    • \n
    • Moving around with link-to
    • \n
    • Using the model property
    • \n
    • Showing a list of bands
    • \n
    • Showing a list of songs
    • \n
  • \n
  • Nested routes\n\n
      \n
    • Defining the nested routes
    • \n
    • Full route names
    • \n
    • Backstage - Resource routes
    • \n
    • Stepping through a router transition
    • \n
    • Backstage - Computed properties
    • \n
    • Nested templates
    • \n
    • {{outlet}} is the default template for routes
    • \n
  • \n
  • Actions\n\n
      \n
    • Extracting model classes
    • \n
    • The class-level mutable attribute property
    • \n
    • Capturing the event
    • \n
    • Turning event into intent
    • \n
  • \n
  • Components\n\n
      \n
    • The idea behind components
    • \n
    • Component specification
    • \n
    • Defining the component's properties
    • \n
    • Using the component
    • \n
    • Displaying the rating with stars
    • \n
    • Backstage - The default component template
    • \n
    • Backstage - On the utility of explicit dependency definitions
    • \n
    • Speaking to the outside world through actions
    • \n
    • Closure actions
    • \n
  • \n
  • Controllers\n\n
      \n
    • Preventing the creation of bands without a name
    • \n
    • Smooth UI flows
    • \n
    • Going to the band page after it is created
    • \n
    • Nudging the user to create the first song
    • \n
    • Showing the text field when the call to action has been acted on
    • \n
    • Creating new bands and songs by pressing return
    • \n
    • Backstage - Where to handle actions?
    • \n
  • \n
  • Advanced routing\n\n
      \n
    • Route hooks
    • \n
    • Route actions
    • \n
    • Redirection
    • \n
    • Redirecting before the model is known
    • \n
    • Redirecting after the model is known
    • \n
    • Backstage - Skipping model resolution
    • \n
    • Leaving routes and arriving at them
    • \n
    • Setting descriptive page titles
    • \n
    • Warning about losing data
    • \n
  • \n
  • Talking to a backend - with Ember Data\n\n
      \n
    • The concept behind Ember Data
    • \n
    • The API
    • \n
    • Model classes
    • \n
    • Transforming the app to use Ember Data
    • \n
    • Loading bands
    • \n
    • Fetching a single band
    • \n
    • Loading songs for a band
    • \n
    • Creating a band
    • \n
    • Updating a band's description
    • \n
    • Updating song ratings
    • \n
    • Backstage - Promises
    • \n
  • \n
  • Testing\n\n
      \n
    • Clarifying the vocabulary
    • \n
    • Acceptance tests
    • \n
    • To mock or not to mock?
    • \n
    • Unit tests
    • \n
    • Integration tests
    • \n
    • Adding an acceptance test
    • \n
    • Analyzing an Ember acceptance test
    • \n
    • Making the first test pass
    • \n
    • Safeguarding critical user scenarios
    • \n
    • Creating a band
    • \n
    • Creating a song
    • \n
    • Backstage \u2013 Fake synchronous tests
    • \n
    • Writing your own test helpers
    • \n
    • Registering a synchronous helper
    • \n
    • Registering an async helper
    • \n
    • Refactoring stubs
    • \n
    • Integration tests in Ember
    • \n
    • Unit tests in Ember
    • \n
  • \n
  • Sorting and searching with query parameters\n\n
      \n
    • Query parameters
    • \n
    • Query parameters in Ember
    • \n
    • Sorting the list of songs
    • \n
    • Sorting an array of items
    • \n
    • Backstage - Computed property macros
    • \n
    • Changing the sorting criteria
    • \n
    • Filtering songs by a search term
    • \n
    • Adding a dash of query parameters
    • \n
    • Using links instead of buttons
    • \n
    • Taking a look at what we made
    • \n
  • \n
  • Loading and error routes\n\n
      \n
    • Loading routes
    • \n
    • Backstage - Rendering the loading template is an overridable default
    • \n
    • Error routes
    • \n
  • \n
  • Helpers\n\n
      \n
    • About helpers
    • \n
    • Capitalizing each word of a name
    • \n
    • Using it in templates, or elsewhere
    • \n
    • Use dashed names for helpers
    • \n
  • \n
  • Animations\n\n
      \n
    • Setting up liquid-fire
    • \n
    • liquid-fire architecture
    • \n
    • Transition map
    • \n
    • Transition functions
    • \n
    • Template helpers
    • \n
    • Putting it all together
    • \n
    • Debugging transitions
    • \n
    • Animate moving between routes
    • \n
    • Adding a custom animation
    • \n
    • Animate a value change
    • \n
  • \n
  • Making an Ember addon\n\n
      \n
    • What is an Ember addon?
    • \n
    • Developing the addon
    • \n
    • Integrating our addon into our app
    • \n
    • Adding a block form
    • \n
    • Customizing the star-rating component's look and behavior
    • \n
    • Publishing the addon
    • \n
    • Using a published addon from the app
    • \n
  • \n
  • ES2015 - Writing modern JavaScript\n\n
      \n
    • Modernizing the app
    • \n
    • Modules
    • \n
    • Template strings
    • \n
    • Short-hand method definitions
    • \n
    • Replacing var (let & const)
    • \n
    • Arrow functions
    • \n
    • Destructuring
    • \n
    • Other useful ES2015 features
    • \n
    • Backstage - ember-watson
    • \n
    • Computed property macros
    • \n
  • \n
  • Deployment\n\n
      \n
    • FrontPage
    • \n
    • Heroku
    • \n
    • ember-cli-deploy
    • \n
  • \n
  • Afterword\n\n
      \n
    • Your journey with Ember.js
    • \n
  • \n
\n\n
\n\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \"Balint\n
\n\n
\n

About me

\n

Hello there, I'm Balint Erdi.

\n

\n I have a long history of building web applications and have mostly been a back-end\n guy.\n

\n

\n On a grey, chilly February day in 2013 that I\u2019ll never forget (maybe it was\n January?) I got acquainted with Ember.js. Ember.js made that day bright and the\n ones that came after that. After learning the ropes I shifted gears and have been\n proselytizing for Ember since last summer.\n

\n

\n I gave a beginner\u2019s workshop at Eurucamp, and held presentations at Arrrrcamp, The Geek Gathering and EmberFest. I started an Ember.js mailing list, made an introductory\n screencast series and have been sending Ember content to my dear subscribers on a\n weekly basis. I have also written guest articles for Safari Books Online, Firebase\n and Toptal.\n

\n

\n I guess you could say I\u2019m pretty passionate about Ember.\n

\n

\n Oh, and I love rock & roll, obviously.\n

\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Bonus: Exclusive hack.hands() deal

\n
\n
\n
\n
\n

\n hack.hands()\n is your SOS button for live programming support, available 24/7. hack.hands() instantly connects developers with a network of expert programmers at the click of a button. Never get stuck, learn more and keep coding!\n If you buy any package, you will receive $25 to spend on their platform that you can use to get your Ember project unstuck.\n

\n
\n
\n\n
\n
\n
\n
\n
\n

Even though I have worked with Ember for the past 6 months, the book helped clarify a lot of things, especially new features and their deprecated counterparts. Such a great book, and looking forward to the second one!

\n
\n
\n
\n \"David\n
\n
\n — David Tang\n
\n
\n
\n
\n\n
\n
\n
\n

There is almost nowhere to go to get a good grounding in Ember. In months of searching this is the best resource that exists... so much so I'm going to try to get a few copies sorted out for my team at work. Thanks Balint!

\n
\n
\n
\n \"\n
\n
\n — Andy Davison\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n

Stairway to Heaven Package

\n
\n
\n
\n\n
\n
\n

\n The path to Ember.js bliss, this package contains all you need to take your Ember.js skills to the next level. It contains:

\n \"Stairway\n

\n
\n
\n
\n\n
\n
\n
\n
\n
\n

This was a truly great series of screencasts. Very, very well done. Simple enough while not being simplistic.

\n
\n
\n
\n \"Claude\n
\n
\n — Claude Pr\u00e9court\n
\n
\n
\n
\n\n
\n
\n
\n

Nice work with these Ember tutorials. You're doing a really nice thing for the community.

\n
\n
\n
\n \"Steven\n
\n
\n — Steven Kane\n
\n
\n
\n
\n
\n
\n
\n \n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Code\"\n
\n

Access to the code

\n All of the source code\n

in the application so that you can check how the app looks & works at each step. Or tweak it to your liking.

\n
\n
\n\n
\n
\n
\n \"Screencast\"\n
\n

Screencasts

\n 4 screencasts\n

They run around 10 minutes each and cover the following,\n advanced topics: Pods in Ember CLI, Animations,\n Authentication & Authorization, and ES2015 &\n computed macros.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n
\n
\n\n
\n \n
\n\n
\n
\n\n \n
\n
\n
\n
\n
\n

Light my Fire Package

\n
\n
\n
\n\n
\n
\n

\n Take out the screencasts and you have this smaller package that will still ignite your Ember rocket. It contains:\n \"Light\n

\n
\n
\n
\n
\n\n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Code\"\n
\n

Access to the code

\n All of the source code\n

in the application so that you can check how the app looks & works at each step. Or tweak it to your liking.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n
\n
\n\n
\n \n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n

Smoke on the Water Package

\n
\n
\n
\n\n
\n
\n

\n Basic but still solid, as the name suggests. This package inclues the book and the hack.hands() deal. It contains:\n

\n \"Smoke\n

\n
\n
\n
\n
\n\n
\n
\n
\n
\n
\n
\n
\n \"The\n
\n

The book

\n 18 chapters\n

This is what you absolutely need to get up & running with Ember.js. Comes in pdf, mobi and epub formats for your reading pleasure.

\n
\n
\n\n
\n
\n
\n \"Rock\n
\n

Rock & More

\n Includes\n

$25 credit on the hack.hands() platform

\n

60-day refund guarantee

\n
\n
\n\n
\n
\n\n
\n \n
\n\n
\n
\n
\n
\n
\n

I\u2019m REALLY enjoying the book and find it to be very thorough and informative. You\u2019ve done a great job of answering questions I had about various concepts that were not detailed clearly elsewhere.

\n
\n
\n
\n \"Bill\n
\n
\n — Bill White\n Data Visualizations at www.bildwhite.com\n
\n
\n
\n
\n\n
\n
\n
\n

It\u2019s been an invaluable resource in learning Ember and one I would recommend to any developer wanting to get started with the framework.

\n
\n
\n
\n \"Jonathan\n
\n
\n — Jonathan Rowley\n
\n
\n
\n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n \n
\n
\n

Hmm, I\u2019m not sure...

\n
\n
\n
\n\n
\n
    \n
  • \n

    Is the book ready for Ember 2?

    \n

    \n Yes, it is! The app in the book runs Ember (and Ember Data)\n 2 and does not use any deprecated stuff.\n

    \n
  • \n\n
  • \n

    Is this book for me?

    \n

    \n The book starts from the very basics (installing\n ember-cli, writing your first template, etc.) so if you\n completely get Ember, this book is probably not for you. If\n you are just starting out (or about to) or want to\n understand fundamental concepts in Ember, the book is\n definitely for you.\n

    \n
  • \n\n
  • \n

    What if I don't like the book?

    \n

    \n I offer a 60-day moneyback guarantee. No strings attached,\n just send your purchase receipt (or email address) to\n rarwe-book@balinterdi.com or answer to the welcome email\n that you received when you purchased.\n

    \n
  • \n\n
  • \n

    Everything is changing so fast; won't the content be outdated by next week?

    \n

    \n As Ember.js moves towards 3.0, I will keep updating the\n content of the book so that it stays void of deprecation\n warnings and does not promote practices that are no longer\n considered idiomatic. For the 1st edition of the book,\n I released an update once about every four weeks,\n more often than Ember stable versions came out.\n Expect the same for the this book edition.\n

    \n
  • \n\n
  • \n

    I heard Ember is so hard. Will this book help me understand it?

    \n

    \n I think there are a handful of key concepts in Ember.js\n that you need to understand to master it (probably the main\n one among these is routing). Once you understand these,\n Ember is not that hard. The intention of the book is\n to introduce concepts by way of building an actual\n application, so you see them applied in practice right away.\n That also helps the learning process. I also encourage you\n to work through the book as you read it, since that makes\n things sink in even deeper. You have access to the code\n repository if you have purchased the middle- or\n high-tier package. If I failed to explain Ember for you, please\n send me your purchase receipt to rarwe-book@balinterdi.com\n within 60 days of purchase and I\u2019ll issue a refund.\n

    \n
  • \n\n
  • \n

    Is the book DRM protected?

    \n

    \n No, it\u2019s not. If you would like to share it with\n colleagues (or a class), please contact me at rarwe-book@balinterdi.com.

    \n
  • \n\n
  • \n

    What if I buy the book-only package and later realize I want to switch to a higher package?

    \n

    No problem! Just send me your purchase receipt to rarwe-book@balinterdi.com, and I will upgrade you for the difference between the package prices.

    \n
  • \n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n
\n \"60-day\n
\n\n \n
\n
\n

Choose a Package

\n
\n
\n
\n
\n\n
\n
\n
    \n
  • \n

    Smoke on the Water

    \n
    \n
    \n $39\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    • \n
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
  • \n

    Light my Fire

    \n
    \n
    \n $59\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • Access to the code
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
  • \n

    Stairway to Heaven

    \n
    \n
    \n $89\n
    \n
    \n
      \n
    • The book with 18 chapters
    • \n
    • Free book updates until 3.0
    • \n
    • Access to the code
    • \n
    • 4 Screencasts
    • \n
    • $25 credit for hack.hands()
    • \n
    • 60-days money back guarantee
    • \n
    • Rock & Roll!
    • \n
    \n
    \n Buy Now\n
    \n
  • \n
\n
\n
\n
\n
\n \n\n \n
\n
\n
\n
\n\n
\n
\n

This book is a fabulous, approachable, foray into Emberjs that makes the learning curve much less scary. I just wish it had been available sooner for students in my previous classes.

\n
\n
\n
\n \"Matt\n
\n
\n — Matt Hale\n Assistant Professor at the University of Nebraska\n
\n
\n
\n
\n\n
\n
\n
\n

I\u2019ve gone through the first four chapters and I am already loving it.

\n
\n
\n
\n \"Sergio\n
\n
\n — Sergio Arbeo\n EmberMadrid\n
\n
\n
\n
\n
\n
\n
\n \n\n \n \n \n\n \n\n \n \n \n \n\n \n \n\n\n\n"}} {"repo": "sebastianbergmann/phpcpd", "pr_number": 206, "title": "Fixing regressed bug-fix for Issue#147", "state": "closed", "merged_at": null, "additions": 1, "deletions": 1, "files_changed": ["src/CLI/Application.php"], "files_before": {"src/CLI/Application.php": "\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\nnamespace SebastianBergmann\\PHPCPD;\n\nuse const PHP_EOL;\nuse function count;\nuse function printf;\nuse SebastianBergmann\\FileIterator\\Facade;\nuse SebastianBergmann\\PHPCPD\\Detector\\Detector;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\AbstractStrategy;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\StrategyConfiguration;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\SuffixTreeStrategy;\nuse SebastianBergmann\\PHPCPD\\Log\\PMD;\nuse SebastianBergmann\\PHPCPD\\Log\\Text;\nuse SebastianBergmann\\Timer\\ResourceUsageFormatter;\nuse SebastianBergmann\\Timer\\Timer;\nuse SebastianBergmann\\Version;\n\nfinal class Application\n{\n private const VERSION = '7.0';\n\n public function run(array $argv): int\n {\n $this->printVersion();\n\n try {\n $arguments = (new ArgumentsBuilder)->build($argv);\n } catch (Exception $e) {\n print PHP_EOL . $e->getMessage() . PHP_EOL;\n\n return 1;\n }\n\n if ($arguments->version()) {\n return 0;\n }\n\n print PHP_EOL;\n\n if ($arguments->help()) {\n $this->help();\n\n return 0;\n }\n\n $files = (new Facade)->getFilesAsArray(\n $arguments->directories(),\n $arguments->suffixes(),\n '',\n $arguments->exclude()\n );\n\n if (empty($files)) {\n print 'No files found to scan' . PHP_EOL;\n\n return 1;\n }\n\n $config = new StrategyConfiguration($arguments);\n\n try {\n $strategy = $this->pickStrategy($arguments->algorithm(), $config);\n } catch (InvalidStrategyException $e) {\n print $e->getMessage() . PHP_EOL;\n\n return 1;\n }\n\n $timer = new Timer;\n $timer->start();\n\n $clones = (new Detector($strategy))->copyPasteDetection($files);\n\n (new Text)->printResult($clones, $arguments->verbose());\n\n if ($arguments->pmdCpdXmlLogfile()) {\n (new PMD($arguments->pmdCpdXmlLogfile()))->processClones($clones);\n }\n\n print (new ResourceUsageFormatter)->resourceUsage($timer->stop()) . PHP_EOL;\n\n return count($clones) > 0 ? 1 : 0;\n }\n\n private function printVersion(): void\n {\n printf(\n 'phpcpd %s by Sebastian Bergmann.' . PHP_EOL,\n (new Version(self::VERSION, dirname(__DIR__)))->getVersion()\n );\n }\n\n /**\n * @throws InvalidStrategyException\n */\n private function pickStrategy(?string $algorithm, StrategyConfiguration $config): AbstractStrategy\n {\n return match ($algorithm) {\n null, 'rabin-karp' => new DefaultStrategy($config),\n 'suffixtree' => new SuffixTreeStrategy($config),\n default => throw new InvalidStrategyException('Unsupported algorithm: ' . $algorithm),\n };\n }\n\n private function help(): void\n {\n print <<<'EOT'\nUsage:\n phpcpd [options] \n\nOptions for selecting files:\n\n --suffix Include files with names ending in in the analysis\n (default: .php; can be given multiple times)\n --exclude Exclude files with in their path from the analysis\n (can be given multiple times)\n\nOptions for analysing files:\n\n --fuzzy Fuzz variable names\n --min-lines Minimum number of identical lines (default: 5)\n --min-tokens Minimum number of identical tokens (default: 70)\n --algorithm Select which algorithm to use ('rabin-karp' (default) or 'suffixtree')\n --edit-distance Distance in number of edits between two clones (only for suffixtree; default: 5)\n --head-equality Minimum equality at start of clone (only for suffixtree; default 10)\n\nOptions for report generation:\n\n --log-pmd Write log in PMD-CPD XML format to \n\nEOT;\n }\n}\n"}, "files_after": {"src/CLI/Application.php": "\n *\n * For the full copyright and license information, please view the LICENSE\n * file that was distributed with this source code.\n */\nnamespace SebastianBergmann\\PHPCPD;\n\nuse const PHP_EOL;\nuse function count;\nuse function printf;\nuse SebastianBergmann\\FileIterator\\Facade;\nuse SebastianBergmann\\PHPCPD\\Detector\\Detector;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\AbstractStrategy;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\DefaultStrategy;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\StrategyConfiguration;\nuse SebastianBergmann\\PHPCPD\\Detector\\Strategy\\SuffixTreeStrategy;\nuse SebastianBergmann\\PHPCPD\\Log\\PMD;\nuse SebastianBergmann\\PHPCPD\\Log\\Text;\nuse SebastianBergmann\\Timer\\ResourceUsageFormatter;\nuse SebastianBergmann\\Timer\\Timer;\nuse SebastianBergmann\\Version;\n\nfinal class Application\n{\n private const VERSION = '7.0';\n\n public function run(array $argv): int\n {\n $this->printVersion();\n\n try {\n $arguments = (new ArgumentsBuilder)->build($argv);\n } catch (Exception $e) {\n print PHP_EOL . $e->getMessage() . PHP_EOL;\n\n return 1;\n }\n\n if ($arguments->version()) {\n return 0;\n }\n\n print PHP_EOL;\n\n if ($arguments->help()) {\n $this->help();\n\n return 0;\n }\n\n $files = (new Facade)->getFilesAsArray(\n $arguments->directories(),\n $arguments->suffixes(),\n '',\n $arguments->exclude()\n );\n\n if (empty($files)) {\n print 'No files found to scan' . PHP_EOL;\n\n return 0;\n }\n\n $config = new StrategyConfiguration($arguments);\n\n try {\n $strategy = $this->pickStrategy($arguments->algorithm(), $config);\n } catch (InvalidStrategyException $e) {\n print $e->getMessage() . PHP_EOL;\n\n return 1;\n }\n\n $timer = new Timer;\n $timer->start();\n\n $clones = (new Detector($strategy))->copyPasteDetection($files);\n\n (new Text)->printResult($clones, $arguments->verbose());\n\n if ($arguments->pmdCpdXmlLogfile()) {\n (new PMD($arguments->pmdCpdXmlLogfile()))->processClones($clones);\n }\n\n print (new ResourceUsageFormatter)->resourceUsage($timer->stop()) . PHP_EOL;\n\n return count($clones) > 0 ? 1 : 0;\n }\n\n private function printVersion(): void\n {\n printf(\n 'phpcpd %s by Sebastian Bergmann.' . PHP_EOL,\n (new Version(self::VERSION, dirname(__DIR__)))->getVersion()\n );\n }\n\n /**\n * @throws InvalidStrategyException\n */\n private function pickStrategy(?string $algorithm, StrategyConfiguration $config): AbstractStrategy\n {\n return match ($algorithm) {\n null, 'rabin-karp' => new DefaultStrategy($config),\n 'suffixtree' => new SuffixTreeStrategy($config),\n default => throw new InvalidStrategyException('Unsupported algorithm: ' . $algorithm),\n };\n }\n\n private function help(): void\n {\n print <<<'EOT'\nUsage:\n phpcpd [options] \n\nOptions for selecting files:\n\n --suffix Include files with names ending in in the analysis\n (default: .php; can be given multiple times)\n --exclude Exclude files with in their path from the analysis\n (can be given multiple times)\n\nOptions for analysing files:\n\n --fuzzy Fuzz variable names\n --min-lines Minimum number of identical lines (default: 5)\n --min-tokens Minimum number of identical tokens (default: 70)\n --algorithm Select which algorithm to use ('rabin-karp' (default) or 'suffixtree')\n --edit-distance Distance in number of edits between two clones (only for suffixtree; default: 5)\n --head-equality Minimum equality at start of clone (only for suffixtree; default 10)\n\nOptions for report generation:\n\n --log-pmd Write log in PMD-CPD XML format to \n\nEOT;\n }\n}\n"}} {"repo": "jezdez/limechat-whisper", "pr_number": 1, "title": "fix display of #channame or www.link.com", "state": "closed", "merged_at": "2012-08-03T20:35:28Z", "additions": 1, "deletions": 1, "files_changed": ["Whisper.css"], "files_before": {"Whisper.css": "html.normal {\n color: #4b4b4b;\n background-color: white;\n font: 12px/1.3em 'Lucida Grande' sans-serif;\n margin: 0;\n padding: 0;\n}\n\nbody.normal .sender[type=myself]:hover:before {\n content: \"\u2022 \";\n color: #bebebe;\n}\n\nbody.normal a img {\n border: 0;\n}\n\nbody.normal img {\n display: block;\n padding-top: 5px;\n padding-bottom: 5px;\n padding-left: 8px;\n max-width: 95%;\n}\n\nbody.normal a:link, a:visited, a:hover, a:active {\n color: #184586;\n}\n\nbody.normal .text span {\n display: block;\n}\n\nbody.normal .line {\n padding: 0;\n margin: 0;\n background-color: #eee;\n line-height: 130%;\n}\n\nbody.normal .event {\n padding: 0.2em;\n margin: 0;\n color: #363636;\n background: #e5edf7;\n}\n\nbody.normal .event + .event {\n border-top: #fff 1px solid;\n}\n\nbody.normal .text span.message {\n border-bottom: #efefef 1px solid;\n}\n\nbody.normal .text + .event {\n margin-top: -1px;\n}\n\nbody.normal .sender {\n padding: 0.4em 0;\n float: left;\n text-align: right;\n font-weight: bold;\n width: 130px;\n overflow: hidden;\n}\n\nbody.normal .line .message {\n margin: 0 0 0 134px;\n padding: 0.4em;\n color: #303030;\n border-left: 1px solid #dcdcdc;\n background-color: #fff;\n}\n\nbody.normal .event .message {\n margin: 0;\n padding: 0.4em;\n border: 0;\n color: #a6b9c0;\n background: none;\n font: bold 11px \"Helvetica Neue\", Arial, Helvetica, sans-serif;\n}\n\nbody.normal .line .time {\n float: right;\n margin-right: 6px;\n margin-top: 5px;\n margin-left: 4px;\n color: #999;\n font: bold 11px \"Helvetica Neue\", Arial, Helvetica, sans-serif;\n}\n\nbody.normal .line .place {\n display: block;\n color: #999;\n margin: 0;\n font-size: 12px;\n}\n\nbody.normal .event .time {\n margin: 1px 3px;\n float: right;\n text-align: right;\n font-size: 11px;\n color: #a6b9c0;\n}\n\nbody.normal .line[highlight=true] span.message {\n background-color: #ffc;\n}\n\nbody.normal .member {\n text-decoration: none !important;\n color: inherit !important;\n}\n\nbody.normal .member:hover {\n text-decoration: underline;\n}\n\nbody.normal {\n \n}\n\nbody.console {\n \n}\n\nbody[type=channel] {\n \n}\n\nbody[type=talk] {\n \n}\n\nbody[type=console] {\n \n}\n\nbody.normal hr {\n margin: 0;\n padding: 2px;\n border: none;\n background-color: #d33b54;\n height: 2px;\n text-align: center;\n}\n\na {\n \n}\n\n/* lines */\n\n.line[alternate=even] {\n \n}\n\n.line[alternate=odd] {\n \n}\n\n.line[type=action] .sender:before {\n content: \"\";\n}\n\nbody.normal .line[type=action] .sender {\n font-style: italic;\n}\n\nbody.normal .line[type=action] .message {\n background: #eee;\n border-left: none;\n margin: 0 0 0 130px;\n}\n\nbody.normal .url {\n word-break: break-all;\n}\n\nbody.normal .address {\n text-decoration: underline;\n word-break: break-all;\n}\n\nbody.normal .highlight {\n color: #d33b54;\n font-weight: bold;\n}\n\n/* nickname for text messages */\n\nbody.normal .sender[type=myself] {\n color: #333;\n}\n\nbody.normal .sender[type=normal] {\n color: #333;\n}\n\nbody.normal .sender[type=normal][colornumber='0'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='1'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='2'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='3'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='4'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='5'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='6'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='7'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='8'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='9'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='10'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='11'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='12'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='13'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='14'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='15'] {\n \n}\n\n/* message body */\n\nbody.normal .message[type=system] {\n color: #303030;\n}\n\nbody.normal .message[type=error] {\n color: #d14025;\n font-weight: bold;\n}\n\nbody.normal .message[type=reply] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=error_reply] {\n color: #d33b54;\n}\n\nbody.normal .message[type=dcc_send_send] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=dcc_send_receive] {\n color: #153b7c;\n}\n\nbody.normal .message[type=privmsg] {\n \n}\n\nbody.normal .message[type=notice] {\n color: #888;\n}\n\nbody.normal .message[type=action] {\n color: #303030;\n font-style: italic;\n font-weight: bold;\n}\n\nbody.normal .message[type=join] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=part] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=kick] {\n color: #303030;\n}\n\nbody.normal .message[type=quit] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=kill] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=nick] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=mode] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=topic] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=invite] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=wallops] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=debug_send] {\n color: #aaa;\n}\n\nbody.normal .message[type=debug_receive] {\n color: #444;\n}"}, "files_after": {"Whisper.css": "html.normal {\n color: #4b4b4b;\n background-color: white;\n font: 12px/1.3em 'Lucida Grande' sans-serif;\n margin: 0;\n padding: 0;\n}\n\nbody.normal .sender[type=myself]:hover:before {\n content: \"\u2022 \";\n color: #bebebe;\n}\n\nbody.normal a img {\n border: 0;\n}\n\nbody.normal img {\n display: block;\n padding-top: 5px;\n padding-bottom: 5px;\n padding-left: 8px;\n max-width: 95%;\n}\n\nbody.normal a:link, a:visited, a:hover, a:active {\n color: #184586;\n}\n\nbody.normal .text > span {\n display: block;\n}\n\nbody.normal .line {\n padding: 0;\n margin: 0;\n background-color: #eee;\n line-height: 130%;\n}\n\nbody.normal .event {\n padding: 0.2em;\n margin: 0;\n color: #363636;\n background: #e5edf7;\n}\n\nbody.normal .event + .event {\n border-top: #fff 1px solid;\n}\n\nbody.normal .text span.message {\n border-bottom: #efefef 1px solid;\n}\n\nbody.normal .text + .event {\n margin-top: -1px;\n}\n\nbody.normal .sender {\n padding: 0.4em 0;\n float: left;\n text-align: right;\n font-weight: bold;\n width: 130px;\n overflow: hidden;\n}\n\nbody.normal .line .message {\n margin: 0 0 0 134px;\n padding: 0.4em;\n color: #303030;\n border-left: 1px solid #dcdcdc;\n background-color: #fff;\n}\n\nbody.normal .event .message {\n margin: 0;\n padding: 0.4em;\n border: 0;\n color: #a6b9c0;\n background: none;\n font: bold 11px \"Helvetica Neue\", Arial, Helvetica, sans-serif;\n}\n\nbody.normal .line .time {\n float: right;\n margin-right: 6px;\n margin-top: 5px;\n margin-left: 4px;\n color: #999;\n font: bold 11px \"Helvetica Neue\", Arial, Helvetica, sans-serif;\n}\n\nbody.normal .line .place {\n display: block;\n color: #999;\n margin: 0;\n font-size: 12px;\n}\n\nbody.normal .event .time {\n margin: 1px 3px;\n float: right;\n text-align: right;\n font-size: 11px;\n color: #a6b9c0;\n}\n\nbody.normal .line[highlight=true] span.message {\n background-color: #ffc;\n}\n\nbody.normal .member {\n text-decoration: none !important;\n color: inherit !important;\n}\n\nbody.normal .member:hover {\n text-decoration: underline;\n}\n\nbody.normal {\n \n}\n\nbody.console {\n \n}\n\nbody[type=channel] {\n \n}\n\nbody[type=talk] {\n \n}\n\nbody[type=console] {\n \n}\n\nbody.normal hr {\n margin: 0;\n padding: 2px;\n border: none;\n background-color: #d33b54;\n height: 2px;\n text-align: center;\n}\n\na {\n \n}\n\n/* lines */\n\n.line[alternate=even] {\n \n}\n\n.line[alternate=odd] {\n \n}\n\n.line[type=action] .sender:before {\n content: \"\";\n}\n\nbody.normal .line[type=action] .sender {\n font-style: italic;\n}\n\nbody.normal .line[type=action] .message {\n background: #eee;\n border-left: none;\n margin: 0 0 0 130px;\n}\n\nbody.normal .url {\n word-break: break-all;\n}\n\nbody.normal .address {\n text-decoration: underline;\n word-break: break-all;\n}\n\nbody.normal .highlight {\n color: #d33b54;\n font-weight: bold;\n}\n\n/* nickname for text messages */\n\nbody.normal .sender[type=myself] {\n color: #333;\n}\n\nbody.normal .sender[type=normal] {\n color: #333;\n}\n\nbody.normal .sender[type=normal][colornumber='0'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='1'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='2'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='3'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='4'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='5'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='6'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='7'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='8'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='9'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='10'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='11'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='12'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='13'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='14'] {\n \n}\n\nbody.normal .sender[type=normal][colornumber='15'] {\n \n}\n\n/* message body */\n\nbody.normal .message[type=system] {\n color: #303030;\n}\n\nbody.normal .message[type=error] {\n color: #d14025;\n font-weight: bold;\n}\n\nbody.normal .message[type=reply] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=error_reply] {\n color: #d33b54;\n}\n\nbody.normal .message[type=dcc_send_send] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=dcc_send_receive] {\n color: #153b7c;\n}\n\nbody.normal .message[type=privmsg] {\n \n}\n\nbody.normal .message[type=notice] {\n color: #888;\n}\n\nbody.normal .message[type=action] {\n color: #303030;\n font-style: italic;\n font-weight: bold;\n}\n\nbody.normal .message[type=join] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=part] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=kick] {\n color: #303030;\n}\n\nbody.normal .message[type=quit] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=kill] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=nick] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=mode] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=topic] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=invite] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=wallops] {\n color: #a6b9c0;\n}\n\nbody.normal .message[type=debug_send] {\n color: #aaa;\n}\n\nbody.normal .message[type=debug_receive] {\n color: #444;\n}"}} {"repo": "paveltyk/technical-test", "pr_number": 1, "title": "improve CLI", "state": "closed", "merged_at": "2010-09-30T09:53:36Z", "additions": 7, "deletions": 1, "files_changed": ["lib/editor.rb"], "files_before": {"lib/editor.rb": "require 'image'\nrequire 'readline'\n\nclass Editor\n def initialize(output)\n @output = output\n end\n def start\n @output.puts 'Welcome to Image Editor!'\n listen\n end\n\n def listen\n loop do\n cmd = Readline::readline '> ', true\n execute(cmd)\n end\n end\n\n def execute(cmd)\n case cmd\n when /^i (\\d+)+ (\\d+)+$/i\n @image = Image.new($1.to_i, $2.to_i)\n when /^c/i\n @image.clear\n when /^l (\\d+) (\\d+) ([a-z])$/i\n @image.colorize($1.to_i, $2.to_i,$3)\n when /^v (\\d+) (\\d+) (\\d+) ([a-z])$/i\n @image.draw_vertical_segment($1.to_i, $2.to_i, $3.to_i, $4)\n when /^h (\\d+) (\\d+) (\\d+) ([a-z])$/i\n @image.draw_horizontal_segment($1.to_i, $2.to_i, $3.to_i, $4)\n when /^f (\\d+) (\\d+) ([a-z])$/i\n @image.fill($1.to_i, $2.to_i, $3)\n when /^s$/i\n @output.puts @image.to_s\n when /^x$/i\n exit\n else\n puts 'Unknown command'\n end\n end\n \nend"}, "files_after": {"lib/editor.rb": "require 'image'\nrequire 'readline'\n\n# trap SIGINT and restore the state of the terminal\nstty_save = `stty -g`.chomp\ntrap('INT') { system('stty', stty_save); exit }\n\nclass Editor\n def initialize(output)\n @output = output\n end\n def start\n @output.puts 'Welcome to Image Editor!'\n listen\n end\n\n def listen\n loop do\n cmd = Readline::readline '> ', true\n # exit if user press CTRL-D\n exit if cmd.nil?\n execute(cmd)\n end\n end\n\n def execute(cmd)\n case cmd\n when /^i (\\d+)+ (\\d+)+$/i\n @image = Image.new($1.to_i, $2.to_i)\n when /^c/i\n @image.clear\n when /^l (\\d+) (\\d+) ([a-z])$/i\n @image.colorize($1.to_i, $2.to_i,$3)\n when /^v (\\d+) (\\d+) (\\d+) ([a-z])$/i\n @image.draw_vertical_segment($1.to_i, $2.to_i, $3.to_i, $4)\n when /^h (\\d+) (\\d+) (\\d+) ([a-z])$/i\n @image.draw_horizontal_segment($1.to_i, $2.to_i, $3.to_i, $4)\n when /^f (\\d+) (\\d+) ([a-z])$/i\n @image.fill($1.to_i, $2.to_i, $3)\n when /^s$/i\n @output.puts @image.to_s\n when /^x$/i\n exit\n else\n puts 'Unknown command'\n end\n end\n \nend\n"}} {"repo": "nhowell/subdomain-fu", "pr_number": 1, "title": "Path url_for to work on on Rails 4.2", "state": "closed", "merged_at": null, "additions": 14, "deletions": 2, "files_changed": ["lib/subdomain_fu/url_rewriter.rb"], "files_before": {"lib/subdomain_fu/url_rewriter.rb": "require 'action_dispatch/routing/route_set'\n\nmodule ActionDispatch\n module Routing\n class RouteSet #:nodoc:\n def url_for_with_subdomains(options, path_segments=nil)\n if SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port)) || options[:only_path] == false\n options[:only_path] = false if SubdomainFu.override_only_path?\n options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)\n # puts \"options[:host]: #{options[:host].inspect}\"\n else\n options.delete(:subdomain)\n end\n url_for_without_subdomains(options)\n end\n alias_method_chain :url_for, :subdomains\n end\n end\nend\n"}, "files_after": {"lib/subdomain_fu/url_rewriter.rb": "require 'action_dispatch/routing/route_set'\n\nmodule ActionDispatch\n module Routing\n class RouteSet #:nodoc:\n # Known Issue: Monkey-patching `url_for` is error-prone.\n # For example, in rails 4.2, the method signature changed from\n #\n # def url_for(options)\n #\n # to\n #\n # def url_for(options, route_name = nil, url_strategy = UNKNOWN)\n #\n # Is there an alternative design using composition or class\n # inheritance?\n\n def url_for_with_subdomains(options, *args)\n if SubdomainFu.needs_rewrite?(options[:subdomain], (options[:host] || @request.host_with_port)) || options[:only_path] == false\n options[:only_path] = false if SubdomainFu.override_only_path?\n options[:host] = SubdomainFu.rewrite_host_for_subdomains(options.delete(:subdomain), options[:host] || @request.host_with_port)\n # puts \"options[:host]: #{options[:host].inspect}\"\n else\n options.delete(:subdomain)\n end\n url_for_without_subdomains(options, *args)\n end\n alias_method_chain :url_for, :subdomains\n end\n end\nend\n"}} {"repo": "jcsalterego/nagios-rb", "pr_number": 1, "title": "unbreak adding further options", "state": "closed", "merged_at": "2012-02-16T16:25:17Z", "additions": 1, "deletions": 1, "files_changed": ["lib/nagios/config.rb"], "files_before": {"lib/nagios/config.rb": "require 'optparse'\n\nmodule Nagios\n class Config\n\n attr_accessor :options\n\n def initialize\n @settings = {}\n @options = OptionParser.new do |options|\n options.on(\"-wWARNING\",\n \"--warning=WARNING\",\n \"Warning Threshold\") do |x|\n @settings[:warning] = int_if_possible(x)\n end\n options.on(\"-cCRITICAL\",\n \"--critical=CRITICAL\",\n \"Critical Threshold\") do |x|\n @settings[:critical] = int_if_possible(x)\n end\n end\n end\n\n def [](setting)\n @settings[setting]\n end\n\n def []=(field, value)\n @settings[field] = vaule\n end\n\n def parse!\n @options.parse!\n end\n\n private\n def int_if_possible(x)\n (x.to_i > 0 || x == '0') ? x.to_i : x\n end\n end\nend\n"}, "files_after": {"lib/nagios/config.rb": "require 'optparse'\n\nmodule Nagios\n class Config\n\n attr_accessor :options\n\n def initialize\n @settings = {}\n @options = OptionParser.new do |options|\n options.on(\"-wWARNING\",\n \"--warning=WARNING\",\n \"Warning Threshold\") do |x|\n @settings[:warning] = int_if_possible(x)\n end\n options.on(\"-cCRITICAL\",\n \"--critical=CRITICAL\",\n \"Critical Threshold\") do |x|\n @settings[:critical] = int_if_possible(x)\n end\n end\n end\n\n def [](setting)\n @settings[setting]\n end\n\n def []=(field, value)\n @settings[field] = value\n end\n\n def parse!\n @options.parse!\n end\n\n private\n def int_if_possible(x)\n (x.to_i > 0 || x == '0') ? x.to_i : x\n end\n end\nend\n"}} {"repo": "aconbere/evented", "pr_number": 1, "title": "Correct the URL for the github repo.", "state": "open", "merged_at": null, "additions": 1, "deletions": 1, "files_changed": ["lib/evented.js"], "files_before": {"lib/evented.js": "/*\n * YO check out the repository for updates\n * http://github.com/aconbere/event-emitter\n *\n */\nvar Evented = function () {\n this.listeners = {};\n this.listenersOnce = {};\n};\n\nEvented.prototype.withListeners = function (ev, callback) {\n if (!this.listeners[ev]) {\n this.listeners[ev] = [];\n }\n\n if (!this.listenersOnce[ev]) {\n this.listenersOnce[ev] = [];\n }\n\n if (callback) {\n callback(this.listeners[ev], this.listenersOnce[ev]);\n }\n};\n\nEvented.prototype.trigger = function (ev, data) {\n data = data || [];\n\n var that = this;\n this.withListeners(ev, function (listeners, listenersOnce) {\n for (var i = 0; i < listeners.length; i++) {\n listeners[i].apply(null, data);\n }\n\n for (var i = 0; i < listenersOnce.length; i++) {\n listenersOnce[i].apply(null, data);\n }\n // reset any of the once listeners for this event\n that.listenersOnce[ev] = [];\n });\n};\n\n\nEvented.prototype.bind = function (ev, callback) {\n this.withListeners(ev, function (listeners, _listenersOnce) {\n listeners.push(callback);\n });\n};\n\nEvented.prototype.bindOnce = function (ev, callback) {\n this.withListeners(ev, function (_listeners, listenersOnce) {\n listenersOnce.push(callback);\n });\n};\n\nEvented.prototype.unbindAll = function () {\n this.listeners = {};\n};\n\nif (typeof window === \"undefined\") {\n exports.Evented = Evented;\n}\n"}, "files_after": {"lib/evented.js": "/*\n * YO check out the repository for updates\n * http://github.com/aconbere/evented\n *\n */\nvar Evented = function () {\n this.listeners = {};\n this.listenersOnce = {};\n};\n\nEvented.prototype.withListeners = function (ev, callback) {\n if (!this.listeners[ev]) {\n this.listeners[ev] = [];\n }\n\n if (!this.listenersOnce[ev]) {\n this.listenersOnce[ev] = [];\n }\n\n if (callback) {\n callback(this.listeners[ev], this.listenersOnce[ev]);\n }\n};\n\nEvented.prototype.trigger = function (ev, data) {\n data = data || [];\n\n var that = this;\n this.withListeners(ev, function (listeners, listenersOnce) {\n for (var i = 0; i < listeners.length; i++) {\n listeners[i].apply(null, data);\n }\n\n for (var i = 0; i < listenersOnce.length; i++) {\n listenersOnce[i].apply(null, data);\n }\n // reset any of the once listeners for this event\n that.listenersOnce[ev] = [];\n });\n};\n\n\nEvented.prototype.bind = function (ev, callback) {\n this.withListeners(ev, function (listeners, _listenersOnce) {\n listeners.push(callback);\n });\n};\n\nEvented.prototype.bindOnce = function (ev, callback) {\n this.withListeners(ev, function (_listeners, listenersOnce) {\n listenersOnce.push(callback);\n });\n};\n\nEvented.prototype.unbindAll = function () {\n this.listeners = {};\n};\n\nif (typeof window === \"undefined\") {\n exports.Evented = Evented;\n}\n"}} {"repo": "jtauber/web-graphics", "pr_number": 1, "title": "Fixed 'open' to write binary data in Windows too", "state": "closed", "merged_at": "2013-08-23T12:31:06Z", "additions": 1, "deletions": 1, "files_changed": ["web_graphics.py"], "files_before": {"web_graphics.py": "import zlib\nimport struct\nimport array\nimport random\nimport colorsys\n\n\ndef output_chunk(out, chunk_type, data):\n out.write(struct.pack(\"!I\", len(data)))\n out.write(chunk_type)\n out.write(data)\n checksum = zlib.crc32(data, zlib.crc32(chunk_type))\n out.write(struct.pack(\"!i\", checksum))\n\n\ndef get_data(width, height, rgb_func):\n fw = float(width)\n fh = float(height)\n compressor = zlib.compressobj()\n data = array.array(\"B\")\n for y in range(height):\n data.append(0)\n fy = float(y)\n for x in range(width):\n fx = float(x)\n data.extend([min(255, max(0, int(v * 255))) for v in rgb_func(fx / fw, fy / fh)])\n compressed = compressor.compress(data.tostring())\n flushed = compressor.flush()\n return compressed + flushed\n\n\ndef write_png(filename, width, height, rgb_func):\n out = open(filename, \"w\")\n out.write(struct.pack(\"8B\", 137, 80, 78, 71, 13, 10, 26, 10))\n output_chunk(out, \"IHDR\", struct.pack(\"!2I5B\", width, height, 8, 2, 0, 0, 0))\n output_chunk(out, \"IDAT\", get_data(width, height, rgb_func))\n output_chunk(out, \"IEND\", \"\")\n out.close()\n\n\ndef linear_gradient(start_value, stop_value, start_offset=0.0, stop_offset=1.0):\n return lambda offset: (start_value + ((offset - start_offset) / (stop_offset - start_offset) * (stop_value - start_value))) / 255.0\n\n\ndef LINEAR_Y(x, y):\n return y\n\n\ndef LINEAR_X(x, y):\n return x\n\n\ndef RADIAL(center_x, center_y):\n return lambda x, y: (x - center_x) ** 2 + (y - center_y) ** 2\n\n\ndef NO_NOISE(r, g, b):\n return r, g, b\n\n\ndef GAUSSIAN(sigma):\n def add_noise(r, g, b):\n d = random.gauss(0, sigma)\n return r + d, g + d, b + d\n return add_noise\n\n\ndef HSV(h, s, v):\n r, g, b = colorsys.hsv_to_rgb(h, s, v)\n return 255 * r, 255 * g, 255 * b\n\n\ndef hexstring_to_rgb(s):\n r = int(s[1:3], 16)\n g = int(s[3:5], 16)\n b = int(s[5:7], 16)\n return r, g, b\n\n\ndef gradient(value_func, noise_func, DATA):\n def gradient_function(x, y):\n initial_offset = 0.0\n v = value_func(x, y)\n for offset, start, end in DATA:\n if isinstance(start, str) and start.startswith(\"#\"):\n start = hexstring_to_rgb(start)\n if isinstance(end, str) and end.startswith(\"#\"):\n end = hexstring_to_rgb(end)\n if v < offset:\n r = linear_gradient(start[0], end[0], initial_offset, offset)(v)\n g = linear_gradient(start[1], end[1], initial_offset, offset)(v)\n b = linear_gradient(start[2], end[2], initial_offset, offset)(v)\n return noise_func(r, g, b)\n initial_offset = offset\n return noise_func(end[0] / 255.0, end[1] / 255.0, end[2] / 255.0)\n return gradient_function\n"}, "files_after": {"web_graphics.py": "import zlib\nimport struct\nimport array\nimport random\nimport colorsys\n\n\ndef output_chunk(out, chunk_type, data):\n out.write(struct.pack(\"!I\", len(data)))\n out.write(chunk_type)\n out.write(data)\n checksum = zlib.crc32(data, zlib.crc32(chunk_type))\n out.write(struct.pack(\"!i\", checksum))\n\n\ndef get_data(width, height, rgb_func):\n fw = float(width)\n fh = float(height)\n compressor = zlib.compressobj()\n data = array.array(\"B\")\n for y in range(height):\n data.append(0)\n fy = float(y)\n for x in range(width):\n fx = float(x)\n data.extend([min(255, max(0, int(v * 255))) for v in rgb_func(fx / fw, fy / fh)])\n compressed = compressor.compress(data.tostring())\n flushed = compressor.flush()\n return compressed + flushed\n\n\ndef write_png(filename, width, height, rgb_func):\n out = open(filename, \"wb\")\n out.write(struct.pack(\"8B\", 137, 80, 78, 71, 13, 10, 26, 10))\n output_chunk(out, \"IHDR\", struct.pack(\"!2I5B\", width, height, 8, 2, 0, 0, 0))\n output_chunk(out, \"IDAT\", get_data(width, height, rgb_func))\n output_chunk(out, \"IEND\", \"\")\n out.close()\n\n\ndef linear_gradient(start_value, stop_value, start_offset=0.0, stop_offset=1.0):\n return lambda offset: (start_value + ((offset - start_offset) / (stop_offset - start_offset) * (stop_value - start_value))) / 255.0\n\n\ndef LINEAR_Y(x, y):\n return y\n\n\ndef LINEAR_X(x, y):\n return x\n\n\ndef RADIAL(center_x, center_y):\n return lambda x, y: (x - center_x) ** 2 + (y - center_y) ** 2\n\n\ndef NO_NOISE(r, g, b):\n return r, g, b\n\n\ndef GAUSSIAN(sigma):\n def add_noise(r, g, b):\n d = random.gauss(0, sigma)\n return r + d, g + d, b + d\n return add_noise\n\n\ndef HSV(h, s, v):\n r, g, b = colorsys.hsv_to_rgb(h, s, v)\n return 255 * r, 255 * g, 255 * b\n\n\ndef hexstring_to_rgb(s):\n r = int(s[1:3], 16)\n g = int(s[3:5], 16)\n b = int(s[5:7], 16)\n return r, g, b\n\n\ndef gradient(value_func, noise_func, DATA):\n def gradient_function(x, y):\n initial_offset = 0.0\n v = value_func(x, y)\n for offset, start, end in DATA:\n if isinstance(start, str) and start.startswith(\"#\"):\n start = hexstring_to_rgb(start)\n if isinstance(end, str) and end.startswith(\"#\"):\n end = hexstring_to_rgb(end)\n if v < offset:\n r = linear_gradient(start[0], end[0], initial_offset, offset)(v)\n g = linear_gradient(start[1], end[1], initial_offset, offset)(v)\n b = linear_gradient(start[2], end[2], initial_offset, offset)(v)\n return noise_func(r, g, b)\n initial_offset = offset\n return noise_func(end[0] / 255.0, end[1] / 255.0, end[2] / 255.0)\n return gradient_function\n"}} {"repo": "chnm/thatcamp-registrations", "pr_number": 28, "title": "Simplifies user creation.", "state": "closed", "merged_at": "2012-02-09T21:10:49Z", "additions": 5, "deletions": 18, "files_changed": ["thatcamp-registrations-functions.php"], "files_before": {"thatcamp-registrations-functions.php": "prefix . \"thatcamp_registrations\";\n \n $_POST = stripslashes_deep($_POST); \n \n // The user_id is set to the posted user ID, or null.\n $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null;\n \n $applicant_info = array();\n \n // Array of applicant info fields. May set up an option in plugin so admins can modify this list.\n $applicant_fields = array(\n 'first_name',\n 'last_name',\n 'user_email',\n 'user_url',\n 'description',\n 'previous_thatcamps',\n 'user_title',\n 'user_organization',\n 'user_twitter',\n 'tshirt_size',\n 'dietary_preferences'\n );\n \n foreach ( $applicant_fields as $field) {\n $applicant_info[$field] = isset($_POST[$field]) ? $_POST[$field] : null;\n }\n \n $date = isset($_POST['date']) ? $_POST['date'] : null;\n $applicationText = isset($_POST['application_text']) ? $_POST['application_text'] : null;\n\n // Let's serialize the applicant_info before putting it in the database.\n $applicant_info = maybe_serialize($applicant_info);\n $applicant_email = isset($_POST['user_email']) ? $_POST['user_email'] : null;\n \n if ( $registration = thatcamp_registrations_get_registration_by_user_id($user_id) \n || $registration = thatcamp_registrations_get_registration_by_applicant_email($applicant_email) ) {\n return 'You have already submitted an application.';\n } else {\n $wpdb->insert(\n $table,\n array(\n 'applicant_info' => $applicant_info,\n 'applicant_email' => $applicant_email,\n 'application_text' => $applicationText,\n 'status' => $status,\n 'date' => $date,\n 'user_id' => $user_id\n )\n );\n thatcamp_registrations_send_applicant_email($applicant_email);\n }\n}\n\n/**\n * Returns registration records based on type\n * \n * @param array The parameters on which to retrieve registrations\n **/\nfunction thatcamp_registrations_get_registrations($params = array()) {\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n \n $sql = \"SELECT * FROM \" . $registrations_table;\n \n if( isset($params['id']) && $id = $params['id']) {\n $sql .= \" WHERE id=\".$params['id'];\n if( isset($params['status']) && $status = $params['status']) {\n $sql .= \" AND status = CONVERT( _utf8 '$status' USING latin1 )\";\n }\n } elseif ( isset($params['status']) && $status = $params['status']) {\n $sql .= \" WHERE status = CONVERT( _utf8 '$status' USING latin1 )\";\n }\n \n // echo $sql; exit;\n $results = $wpdb->get_results($sql, OBJECT);\n return $results;\n}\n\n/**\n * Processes an array of registrations based on ID. Used mainly in the admin.\n * \n * @param array The IDs of the registration records.\n * @param string The status for the registration records.\n **/\nfunction thatcamp_registrations_process_registrations($ids = array(), $status) {\n global $wpdb;\n $table = $wpdb->prefix . \"thatcamp_registrations\";\n \n $idArray = array();\n foreach ($ids as $id) {\n $idArray['id'] = $id;\n }\n \n if ($status && !empty($idArray)) { \n $wpdb->update(\n $table,\n array('status' => $status),\n $idArray\n );\n if ($status == 'approved' && thatcamp_registrations_create_user_accounts()) {\n foreach ($ids as $id) {\n thatcamp_registrations_process_user($id);\n }\n }\n }\n \n return;\n}\n\n/**\n * Process a single registration based on ID. Uses mainly in the admin.\n * \n * @param int The ID of the registration record.\n * @param string The status for the registration record.\n **/\nfunction thatcamp_registrations_process_registration($id, $status) {\n if (isset($id) && isset($status)) {\n thatcamp_registrations_process_registrations(array($id), $status);\n }\n return;\n}\n\n/**\n * Processes a WP user when adding/updating a registration record. Only \n * should be used if we're creating users with approved registrations.\n *\n * @param integer|null The User ID\n * @param array The array of user information.\n * @param $registrationId\n * @return integer The User ID\n **/\nfunction thatcamp_registrations_process_user($registrationId = null, $role = 'author') {\n global $wpdb;\n \n /**\n * If the Registration ID is set, it means we already have a registration \n * record! Booyah. We'll use the user_id and application_info columns from \n * that record to process the user.\n */\n \n if ($registration = thatcamp_registrations_get_registration_by_id($registrationId)) { \n \n $userInfo = maybe_unserialize($registration->applicant_info);\n $userId = $registration->user_id ? $registration->user_id : email_exists($registration->applicant_email);\n \n // If we have a valid a User ID, we're dealing with an existing user.\n if ($userId) {\n add_existing_user_to_blog(array('user_id' => $userId, 'role' => $role));\n wp_new_user_notification($userId);\n }\n // We're probably dealing with a new user. Let's create one and associate it to our blog.\n else { \n $randomPassword = wp_generate_password( 12, false );\n $userEmail = $registration->applicant_email;\n $uarray = split( '@', $userEmail );\n $userName = sanitize_user( $uarray[0] );\n $userId = wp_create_user( $userName, $randomPassword, $userEmail );\n add_user_to_blog($wpdb->blogid, $userId, $role);\n thatcamp_registrations_update_user_data($userId, $userInfo);\n wp_new_user_notification($userId, $randomPassword);\n }\n }\n \n return $userId;\n}\n\n/**\n * Updates the user data. \n * Note: this needs to be altered so that user_url goes in the wp_users table and not the wp_usermeta table. --AF Sample: wp_update_user( array ('ID' => $user_id, 'user_url' => 'http://www.site.com' ) ) ; and http://wordpress.org/support/topic/wordpress-33-update_user_meta-and-wp_userswp_usermeta-issue?replies=8 \n **/\nfunction thatcamp_registrations_update_user_data($userId, $params)\n{\n\n if ( isset( $userId ) && $userData = get_userdata($userId) ) {\n foreach ($params as $key => $value) {\n update_user_meta( $userId, $key, $value );\n }\n } \n}\n\n/**\n * Gets registration record by ID.\n *\n **/\nfunction thatcamp_registrations_get_registration_by_id($id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE id = \" .$id;\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Gets registration record by applicant_email.\n *\n **/\nfunction thatcamp_registrations_get_registration_by_applicant_email($applicant_email)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE applicant_email = '\" .$applicant_email .\"'\";\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Gets registration record by user_id.\n *\n * @param int $user_id The User ID.\n * @return object Registration record.\n **/\nfunction thatcamp_registrations_get_registration_by_user_id($user_id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE user_id = \" .$user_id;\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Deletes a registration record by ID.\n *\n **/\nfunction thatcamp_registrations_delete_registration($id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n if($id) {\n $wpdb->query(\"DELETE FROM \" . $registrations_table . \" WHERE id = '\" . $id . \"'\");\n }\n}\n\n/**\n * Creates a user from a registration record.\n *\n * @param integer $registrationId \n **/\nfunction thatcamp_registrations_create_user($registrationId)\n{\n if ($applicant = thatcamp_registrations_get_registration_applicant($registrationId)) {\n \n // if ( !is_int($applicant) ) {\n return $applicant;\n // }\n }\n}\n\n/**\n * Returns the value for thatcamp_registrations_options\n *\n * @uses get_option()\n * @return array The array of options\n **/\nfunction thatcamp_registrations_options() \n{\n return get_option('thatcamp_registrations_options');\n}\n\n/**\n * Returns the value for a single THATCamp Registrations option.\n *\n * @uses thatcamp_registrations_options()\n * @param string The name of the option\n * @return string\n **/\nfunction thatcamp_registrations_option($optionName) \n{\n if (isset($optionName)) {\n $options = thatcamp_registrations_options();\n return $options[$optionName];\n }\n return false;\n}\n\nfunction thatcamp_registrations_get_applicant_info($registration) \n{\n global $wpdb;\n \n if ($registration) {\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE id = \" .$registration->id;\n $record = $wpdb->get_row($sql, OBJECT);\n if (($record->user_id == 0 || $record->user_id == null) && !empty($record->applicant_info)) {\n return (object) maybe_unserialize($record->applicant_info);\n } else {\n return get_userdata($record->user_id);\n }\n }\n}\n\n/**\n * Send a notification email to a THATCamp Registrations applicant\n *\n * @param string The applicant email address.\n * @param string The status of the application. Options are 'pending',\n * 'approved', and 'rejected. Default is pending.\n */\nfunction thatcamp_registrations_send_applicant_email($to, $status = \"pending\")\n{\n if (is_email($to)) {\n switch ($status) {\n case 'approved':\n $subject = __('Application Approved', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('accepted_application_email');\n break;\n \n case 'rejected':\n $subject = __('Application Rejected', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('rejected_application_email');\n break;\n case 'pending':\n default:\n $subject = __('Application Pending', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('pending_application_email');\n break;\n }\n \n $subject = $subject . ': '.get_bloginfo('name');\n wp_mail($to, $subject, $message);\n \n return __('Email successfully sent!');\n }\n return false;\n}\n\n/**\n * Checks the option to create user accounts upon application approval.\n *\n * @return boolean\n **/\nfunction thatcamp_registrations_create_user_accounts() \n{\n return (bool) thatcamp_registrations_option('create_user_accounts');\n}\n\n/**\n * Checks to see if user authentication is required.\n *\n * @return boolean\n **/\nfunction thatcamp_registrations_user_required() \n{\n return (bool) thatcamp_registrations_option('require_login');\n}\n\n/**\n * Checks if registration is open.\n *\n * @return boolean\n */\nfunction thatcamp_registrations_registration_is_open()\n{\n return (bool) thatcamp_registrations_option('open_registration');\n}\n\n/**\n * Generates a random string for a token\n **/\nfunction thatcamp_registrations_generate_token()\n{\n return sha1(microtime() . mt_rand(1, 100000));\n}\n"}, "files_after": {"thatcamp-registrations-functions.php": "prefix . \"thatcamp_registrations\";\n \n $_POST = stripslashes_deep($_POST); \n \n // The user_id is set to the posted user ID, or null.\n $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null;\n \n $applicant_info = array();\n \n // Array of applicant info fields. May set up an option in plugin so admins can modify this list.\n $applicant_fields = array(\n 'first_name',\n 'last_name',\n 'user_email',\n 'user_url',\n 'description',\n 'previous_thatcamps',\n 'user_title',\n 'user_organization',\n 'user_twitter',\n 'tshirt_size',\n 'dietary_preferences'\n );\n \n foreach ( $applicant_fields as $field) {\n $applicant_info[$field] = isset($_POST[$field]) ? $_POST[$field] : null;\n }\n \n $date = isset($_POST['date']) ? $_POST['date'] : null;\n $applicationText = isset($_POST['application_text']) ? $_POST['application_text'] : null;\n\n // Let's serialize the applicant_info before putting it in the database.\n $applicant_info = maybe_serialize($applicant_info);\n $applicant_email = isset($_POST['user_email']) ? $_POST['user_email'] : null;\n \n if ( $registration = thatcamp_registrations_get_registration_by_user_id($user_id) \n || $registration = thatcamp_registrations_get_registration_by_applicant_email($applicant_email) ) {\n return 'You have already submitted an application.';\n } else {\n $wpdb->insert(\n $table,\n array(\n 'applicant_info' => $applicant_info,\n 'applicant_email' => $applicant_email,\n 'application_text' => $applicationText,\n 'status' => $status,\n 'date' => $date,\n 'user_id' => $user_id\n )\n );\n thatcamp_registrations_send_applicant_email($applicant_email);\n }\n}\n\n/**\n * Returns registration records based on type\n * \n * @param array The parameters on which to retrieve registrations\n **/\nfunction thatcamp_registrations_get_registrations($params = array()) {\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n \n $sql = \"SELECT * FROM \" . $registrations_table;\n \n if( isset($params['id']) && $id = $params['id']) {\n $sql .= \" WHERE id=\".$params['id'];\n if( isset($params['status']) && $status = $params['status']) {\n $sql .= \" AND status = CONVERT( _utf8 '$status' USING latin1 )\";\n }\n } elseif ( isset($params['status']) && $status = $params['status']) {\n $sql .= \" WHERE status = CONVERT( _utf8 '$status' USING latin1 )\";\n }\n \n // echo $sql; exit;\n $results = $wpdb->get_results($sql, OBJECT);\n return $results;\n}\n\n/**\n * Processes an array of registrations based on ID. Used mainly in the admin.\n * \n * @param array The IDs of the registration records.\n * @param string The status for the registration records.\n **/\nfunction thatcamp_registrations_process_registrations($ids = array(), $status) {\n global $wpdb;\n $table = $wpdb->prefix . \"thatcamp_registrations\";\n \n $idArray = array();\n foreach ($ids as $id) {\n $idArray['id'] = $id;\n }\n \n if ($status && !empty($idArray)) { \n $wpdb->update(\n $table,\n array('status' => $status),\n $idArray\n );\n if ($status == 'approved' && thatcamp_registrations_create_user_accounts()) {\n foreach ($ids as $id) {\n thatcamp_registrations_process_user($id);\n }\n }\n }\n \n return;\n}\n\n/**\n * Process a single registration based on ID. Uses mainly in the admin.\n * \n * @param int The ID of the registration record.\n * @param string The status for the registration record.\n **/\nfunction thatcamp_registrations_process_registration($id, $status) {\n if (isset($id) && isset($status)) {\n thatcamp_registrations_process_registrations(array($id), $status);\n }\n return;\n}\n\n/**\n * Processes a WP user when adding/updating a registration record. Only \n * should be used if we're creating users with approved registrations.\n *\n * @param integer|null The User ID\n * @param array The array of user information.\n * @param $registrationId\n * @return integer The User ID\n **/\nfunction thatcamp_registrations_process_user($registrationId = null, $role = 'author') {\n global $wpdb;\n \n /**\n * If the Registration ID is set, it means we already have a registration \n * record! Booyah. We'll use the user_id and application_info columns from \n * that record to process the user.\n */\n \n if ($registration = thatcamp_registrations_get_registration_by_id($registrationId)) { \n \n $userInfo = maybe_unserialize($registration->applicant_info);\n $userId = $registration->user_id ? $registration->user_id : email_exists($registration->applicant_email);\n \n // If we have a valid a User ID, we're dealing with an existing user.\n if ($userId) {\n add_existing_user_to_blog(array('user_id' => $userId, 'role' => $role));\n wp_new_user_notification($userId);\n }\n // We're probably dealing with a new user. Let's create one and associate it to our blog.\n else { \n $userEmail = $registration->applicant_email;\n $uarray = split( '@', $userEmail );\n $userName = sanitize_user( $uarray[0] );\n $userInfo['user_login'] = $userName;\n $userInfo['user_email'] = $userEmail;\n\n $userId = wp_insert_user( $userInfo );\n add_user_to_blog($wpdb->blogid, $userId, $role);\n wp_new_user_notification($userId);\n }\n }\n \n return $userId;\n}\n\n/**\n * Gets registration record by ID.\n *\n **/\nfunction thatcamp_registrations_get_registration_by_id($id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE id = \" .$id;\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Gets registration record by applicant_email.\n *\n **/\nfunction thatcamp_registrations_get_registration_by_applicant_email($applicant_email)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE applicant_email = '\" .$applicant_email .\"'\";\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Gets registration record by user_id.\n *\n * @param int $user_id The User ID.\n * @return object Registration record.\n **/\nfunction thatcamp_registrations_get_registration_by_user_id($user_id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE user_id = \" .$user_id;\n return $wpdb->get_row($sql, OBJECT);\n}\n\n/**\n * Deletes a registration record by ID.\n *\n **/\nfunction thatcamp_registrations_delete_registration($id)\n{\n global $wpdb;\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n if($id) {\n $wpdb->query(\"DELETE FROM \" . $registrations_table . \" WHERE id = '\" . $id . \"'\");\n }\n}\n\n/**\n * Creates a user from a registration record.\n *\n * @param integer $registrationId \n **/\nfunction thatcamp_registrations_create_user($registrationId)\n{\n if ($applicant = thatcamp_registrations_get_registration_applicant($registrationId)) {\n \n // if ( !is_int($applicant) ) {\n return $applicant;\n // }\n }\n}\n\n/**\n * Returns the value for thatcamp_registrations_options\n *\n * @uses get_option()\n * @return array The array of options\n **/\nfunction thatcamp_registrations_options() \n{\n return get_option('thatcamp_registrations_options');\n}\n\n/**\n * Returns the value for a single THATCamp Registrations option.\n *\n * @uses thatcamp_registrations_options()\n * @param string The name of the option\n * @return string\n **/\nfunction thatcamp_registrations_option($optionName) \n{\n if (isset($optionName)) {\n $options = thatcamp_registrations_options();\n return $options[$optionName];\n }\n return false;\n}\n\nfunction thatcamp_registrations_get_applicant_info($registration) \n{\n global $wpdb;\n \n if ($registration) {\n $registrations_table = $wpdb->prefix . \"thatcamp_registrations\";\n $sql = \"SELECT * from \" . $registrations_table . \" WHERE id = \" .$registration->id;\n $record = $wpdb->get_row($sql, OBJECT);\n if (($record->user_id == 0 || $record->user_id == null) && !empty($record->applicant_info)) {\n return (object) maybe_unserialize($record->applicant_info);\n } else {\n return get_userdata($record->user_id);\n }\n }\n}\n\n/**\n * Send a notification email to a THATCamp Registrations applicant\n *\n * @param string The applicant email address.\n * @param string The status of the application. Options are 'pending',\n * 'approved', and 'rejected. Default is pending.\n */\nfunction thatcamp_registrations_send_applicant_email($to, $status = \"pending\")\n{\n if (is_email($to)) {\n switch ($status) {\n case 'approved':\n $subject = __('Application Approved', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('accepted_application_email');\n break;\n \n case 'rejected':\n $subject = __('Application Rejected', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('rejected_application_email');\n break;\n case 'pending':\n default:\n $subject = __('Application Pending', 'thatcamp-registrations');\n $message = thatcamp_registrations_option('pending_application_email');\n break;\n }\n \n $subject = $subject . ': '.get_bloginfo('name');\n wp_mail($to, $subject, $message);\n \n return __('Email successfully sent!');\n }\n return false;\n}\n\n/**\n * Checks the option to create user accounts upon application approval.\n *\n * @return boolean\n **/\nfunction thatcamp_registrations_create_user_accounts() \n{\n return (bool) thatcamp_registrations_option('create_user_accounts');\n}\n\n/**\n * Checks to see if user authentication is required.\n *\n * @return boolean\n **/\nfunction thatcamp_registrations_user_required() \n{\n return (bool) thatcamp_registrations_option('require_login');\n}\n\n/**\n * Checks if registration is open.\n *\n * @return boolean\n */\nfunction thatcamp_registrations_registration_is_open()\n{\n return (bool) thatcamp_registrations_option('open_registration');\n}\n\n/**\n * Generates a random string for a token\n **/\nfunction thatcamp_registrations_generate_token()\n{\n return sha1(microtime() . mt_rand(1, 100000));\n}\n"}} {"repo": "roman/warden_oauth", "pr_number": 4, "title": "Added a way to modify the oauth_callback url", "state": "open", "merged_at": null, "additions": 465, "deletions": 4, "files_changed": ["lib/warden_oauth.rb", "lib/warden_oauth/strategy.rb", "lib/warden_oauth2/base.rb", "lib/warden_oauth2/config.rb", "lib/warden_oauth2/config_extension.rb", "lib/warden_oauth2/errors.rb", "lib/warden_oauth2/strategy.rb", "lib/warden_oauth2/strategy_builder.rb", "lib/warden_oauth2/utils.rb"], "files_before": {"lib/warden_oauth/strategy.rb": "module Warden\n module OAuth\n\n #\n # Holds all the main logic of the OAuth authentication, all the generated\n # OAuth classes will extend from this class\n #\n class Strategy < Warden::Strategies::Base\n extend StrategyBuilder\n\n ######################\n ### Strategy Logic ###\n ######################\n\n\n def self.access_token_user_finders\n (@_user_token_finders ||= {})\n end\n\n #\n # An OAuth strategy will be valid to execute if:\n # * A 'warden_oauth_provider' parameter is given, with the name of the OAuth service\n # * A 'oauth_token' is being receive on the request (response from an OAuth provider)\n #\n def valid?\n (params.include?('warden_oauth_provider') && params['warden_oauth_provider'] == config.provider_name.to_s) ||\n params.include?('oauth_token') \n end\n\n\n #\n # Manages the OAuth authentication process, there can be 3 outcomes from this Strategy:\n # 1. The OAuth credentials are invalid and the FailureApp is called\n # 2. The OAuth credentials are valid, but there is no user associated to them. In this case\n # the FailureApp is called, but the env['warden.options'][:oauth][:access_token] will be \n # available.\n # 3. The OAuth credentials are valid, and the user is authenticated successfuly\n #\n # @note\n # If you want to signup users with the twitter credentials, you can manage the creation of a new \n # user in the FailureApp with the given access_token\n #\n def authenticate!\n if params.include?('warden_oauth_provider')\n store_request_token_on_session\n redirect!(request_token.authorize_url)\n throw(:warden)\n elsif params.include?('oauth_token')\n load_request_token_from_session\n if missing_stored_token?\n fail!(\"There is no OAuth authentication in progress\")\n elsif !stored_token_match_recieved_token?\n fail!(\"Received OAuth token didn't match stored OAuth token\")\n else\n user = find_user_by_access_token(access_token)\n if user.nil?\n fail!(\"User with access token not found\")\n throw_error_with_oauth_info\n else\n success!(user)\n end\n end\n end\n\n end\n\n def fail!(msg) #:nodoc:\n self.errors.add(service_param_name.to_sym, msg)\n super\n end\n \n ###################\n ### OAuth Logic ###\n ###################\n\n def consumer\n @consumer ||= ::OAuth::Consumer.new(config.consumer_key, config.consumer_secret, config.options)\n end\n\n def request_token\n host_with_port = Warden::OAuth::Utils.host_with_port(request)\n @request_token ||= consumer.get_request_token(:oauth_callback => host_with_port)\n end\n\n def access_token\n @access_token ||= request_token.get_access_token(:oauth_verifier => params['oauth_verifier'])\n end\n\n protected\n\n def find_user_by_access_token(access_token)\n raise RuntimeError.new(<<-ERROR_MESSAGE) unless self.respond_to?(:_find_user_by_access_token)\n \nYou need to define a finder by access_token for this strategy.\nWrite on the warden initializer the following code:\nWarden::OAuth.access_token_user_finder(:#{config.provider_name}) do |access_token|\n # Logic to get your user from an access_token\nend\n\nERROR_MESSAGE\n self._find_user_by_access_token(access_token)\n end\n\n def throw_error_with_oauth_info\n throw(:warden, :oauth => { \n self.config.provider_name => {\n :provider => config.provider_name,\n :access_token => access_token,\n :consumer_key => config.consumer_key,\n :consumer_secret => config.consumer_secret\n }\n })\n end\n\n def store_request_token_on_session\n session[:request_token] = request_token.token\n session[:request_secret] = request_token.secret\n end\n\n def load_request_token_from_session\n token = session.delete(:request_token)\n secret = session.delete(:request_secret)\n @request_token = ::OAuth::RequestToken.new(consumer, token, secret)\n end\n\n def missing_stored_token? \n !request_token\n end\n\n def stored_token_match_recieved_token?\n request_token.token == params['oauth_token']\n end\n\n def service_param_name\n '%s_oauth' % config.provider_name\n end\n\n def config\n self.class::CONFIG\n end\n\n end\n\n end\nend\n", "lib/warden_oauth.rb": "require \"rack\"\nrequire \"warden\"\nrequire \"oauth\"\n\nmodule Warden\n module OAuth\n\n base_path = File.dirname(__FILE__) + \"/warden_oauth\"\n \n require base_path + \"/base\"\n require base_path + \"/errors\"\n autoload :Utils, base_path + '/utils'\n autoload :StrategyBuilder, base_path + '/strategy_builder'\n autoload :Strategy, base_path + '/strategy'\n autoload :Config, base_path + \"/config\"\n require base_path + \"/config_extension\"\n \n\n end\nend\n"}, "files_after": {"lib/warden_oauth/strategy.rb": "module Warden\n module OAuth\n\n #\n # Holds all the main logic of the OAuth authentication, all the generated\n # OAuth classes will extend from this class\n #\n class Strategy < Warden::Strategies::Base\n extend StrategyBuilder\n\n ######################\n ### Strategy Logic ###\n ######################\n\n\n def self.access_token_user_finders\n (@_user_token_finders ||= {})\n end\n\n #\n # An OAuth strategy will be valid to execute if:\n # * A 'warden_oauth_provider' parameter is given, with the name of the OAuth service\n # * A 'oauth_token' is being receive on the request (response from an OAuth provider)\n #\n def valid?\n (params.include?('warden_oauth_provider') && params['warden_oauth_provider'] == config.provider_name.to_s) ||\n params.include?('oauth_token') \n end\n\n\n #\n # Manages the OAuth authentication process, there can be 3 outcomes from this Strategy:\n # 1. The OAuth credentials are invalid and the FailureApp is called\n # 2. The OAuth credentials are valid, but there is no user associated to them. In this case\n # the FailureApp is called, but the env['warden.options'][:oauth][:access_token] will be \n # available.\n # 3. The OAuth credentials are valid, and the user is authenticated successfuly\n #\n # @note\n # If you want to signup users with the twitter credentials, you can manage the creation of a new \n # user in the FailureApp with the given access_token\n #\n def authenticate!\n if params.include?('warden_oauth_provider')\n store_request_token_on_session\n redirect!(request_token.authorize_url(config.options))\n throw(:warden)\n elsif params.include?('oauth_token')\n load_request_token_from_session\n if missing_stored_token?\n fail!(\"There is no OAuth authentication in progress\")\n elsif !stored_token_match_recieved_token?\n fail!(\"Received OAuth token didn't match stored OAuth token\")\n else\n user = find_user_by_access_token(access_token)\n if user.nil?\n fail!(\"User with access token not found\")\n throw_error_with_oauth_info\n else\n success!(user)\n end\n end\n end\n\n end\n\n def fail!(msg) #:nodoc:\n self.errors.add(service_param_name.to_sym, msg)\n super\n end\n \n ###################\n ### OAuth Logic ###\n ###################\n\n def consumer\n @consumer ||= ::OAuth::Consumer.new(config.consumer_key, config.consumer_secret, config.options)\n end\n\n def request_token\n @request_token ||= consumer.get_request_token(:oauth_callback => config.options[:oauth_callback])\n end\n\n def access_token\n @access_token ||= request_token.get_access_token(:oauth_verifier => params['oauth_verifier'])\n end\n\n protected\n\n def find_user_by_access_token(access_token)\n raise RuntimeError.new(<<-ERROR_MESSAGE) unless self.respond_to?(:_find_user_by_access_token)\n \nYou need to define a finder by access_token for this strategy.\nWrite on the warden initializer the following code:\nWarden::OAuth.access_token_user_finder(:#{config.provider_name}) do |access_token|\n # Logic to get your user from an access_token\nend\n\nERROR_MESSAGE\n self._find_user_by_access_token(access_token)\n end\n\n def throw_error_with_oauth_info\n throw(:warden, :oauth => { \n self.config.provider_name => {\n :provider => config.provider_name,\n :access_token => access_token,\n :consumer_key => config.consumer_key,\n :consumer_secret => config.consumer_secret\n }\n })\n end\n\n def store_request_token_on_session\n session[:request_token] = request_token.token\n session[:request_secret] = request_token.secret\n end\n\n def load_request_token_from_session\n token = session.delete(:request_token)\n secret = session.delete(:request_secret)\n @request_token = ::OAuth::RequestToken.new(consumer, token, secret)\n end\n\n def missing_stored_token? \n !request_token\n end\n\n def stored_token_match_recieved_token?\n request_token.token == params['oauth_token']\n end\n\n def service_param_name\n '%s_oauth' % config.provider_name\n end\n\n def config\n self.class::CONFIG\n end\n\n end\n\n end\nend\n", "lib/warden_oauth.rb": "require \"rack\"\nrequire \"warden\"\nrequire \"oauth\"\n\nmodule Warden\n module OAuth\n\n base_path = File.dirname(__FILE__) + \"/warden_oauth\"\n \n require base_path + \"/base\"\n require base_path + \"/errors\"\n autoload :Utils, base_path + '/utils'\n autoload :StrategyBuilder, base_path + '/strategy_builder'\n autoload :Strategy, base_path + '/strategy'\n autoload :Config, base_path + \"/config\"\n require base_path + \"/config_extension\"\n \n\n end\nend\n\nrequire \"oauth2\"\n\nmodule Warden\n module OAuth2\n\n base_path = File.dirname(__FILE__) + \"/warden_oauth2\"\n \n require base_path + \"/base\"\n require base_path + \"/errors\"\n autoload :Utils, base_path + '/utils'\n autoload :StrategyBuilder, base_path + '/strategy_builder'\n autoload :Strategy, base_path + '/strategy'\n autoload :Config, base_path + \"/config\"\n require base_path + \"/config_extension\"\n \n\n end\nend\n\n"}} {"repo": "railsfactory-shiv/rupees", "pr_number": 2, "title": "Spacing fix", "state": "closed", "merged_at": null, "additions": 43, "deletions": 38, "files_changed": ["lib/rupees.rb"], "files_before": {"lib/rupees.rb": "module NumberToRupees\n WORDS = {0=>\"zero\", 1=>\"One\", 2=>\"Two\", 3=>\"Three\", 4=>\"Four\", 5=>\"Five\", 6=>\"six\", 7=>\"seven\", 8=>\"Eight\", 9=>\"Nine\",10=>\"Ten\",11=>\"Eleven\",12=>\"Twelve\",13=>\"Thirteen\",14=>\"Fourteen\",15=>\"Fifteen\",16=>\"Sixteen\",17=>\"Seventeen\",18=>\"Eighteen\",19=>\"Nineteen\",20=>\"Twenty\",30=>\"Thirty\",40=>\"Fourty\",50=>\"Fifty\",60=>\"Sixty\",70=>\"Seventy\",80=>\"Eighty\",90=>\"Ninty\"}\n SUFIXES = {0=>\"hundred & \", 1=>\" Crore, \", 2=>\" Lakh, \", 3=>\" Thousand, \", 4=>\" Hundred, \"} # 5=>''\n module Fixnum\n def self.included(recipient)\n recipient.extend(ClassMethods)\n recipient.class_eval do\n include InstanceMethods\n end\n end\n \n module ClassMethods\n end\n \n module InstanceMethods\n def rupees\n result = self >= 0 ? \"\" : \"(-) \"\n\t num = self.abs\n \n # I would prefer One Rupee, insead of One Rupees\n return \"One Rupee.\" if num==1\n\t \n if num > 99\n num.to_s.rjust(11,'0').insert(-4,'0').scan(/../).each_with_index{|x,i| result += self.def_calc(x,i) }\n \t else\t \n result = spell_two_digits(num)\n end\n\t result.sub(/,\\s$/,'')+ \" Rupees.\"\n end\n\n protected\n def def_calc(x,i)\n str=self.proc_unit(x)\n\t return '' if str.length==0\n return \"#{str}#{SUFIXES[i]}\"\n end\n\n def proc_unit(x)\n return \"\" unless x.to_i > 0\n return spell_two_digits(x.to_i)\n end\n\t \n\t def spell_two_digits(x)\n return WORDS[x] if WORDS[x]\n r,f = x.divmod(10)\n return \"#{WORDS[r*10]}#{WORDS[f]}\"\n\t end\n end\n end \nend \nFixnum.send :include, NumberToRupees::Fixnum\n"}, "files_after": {"lib/rupees.rb": "module NumberToRupees\n WORDS = { 0 => 'zero', 1 => 'One', 2 => 'Two', 3 => 'Three', 4 => 'Four', 5 => 'Five', 6 => 'six', 7 => 'seven', 8 => 'Eight', 9 => 'Nine',\n 10 => 'Ten', 11 => 'Eleven', 12 => 'Twelve', 13 => 'Thirteen', 14 => 'Fourteen', 15 => 'Fifteen', 16 => 'Sixteen', 17 => 'Seventeen', 18 => 'Eighteen', 19 => 'Nineteen', 20 => 'Twenty', 30 => 'Thirty', 40 => 'Fourty', 50 => 'Fifty', 60 => 'Sixty', 70 => 'Seventy', 80 => 'Eighty', 90 => 'Ninty' }\n SUFIXES = { 0 => 'hundred & ', 1 => ' Crore, ', 2 => ' Lakh, ', 3 => ' Thousand, ', 4 => ' Hundred, ' } # 5=>''\n module Integer\n def self.included(recipient)\n recipient.extend(ClassMethods)\n recipient.class_eval do\n include InstanceMethods\n end\n end\n\n module ClassMethods\n end\n\n module InstanceMethods\n def rupees\n result = self >= 0 ? '' : '(-) '\n num = abs\n\n # I would prefer One Rupee, insead of One Rupees\n return 'One Rupee.' if num == 1\n\n if num > 99\n num.to_s.rjust(11, '0').insert(-4, '0').scan(/../).each_with_index { |x, i| result += def_calc(x, i) }\n else\n result = spell_two_digits(num)\n end\n result.sub(/,\\s$/, '')\n end\n\n protected\n\n def def_calc(x, i)\n str = proc_unit(x)\n return '' if str.length == 0\n\n \"#{str}#{SUFIXES[i]}\"\n end\n\n def proc_unit(x)\n return '' unless x.to_i > 0\n\n spell_two_digits(x.to_i)\n end\n\n def spell_two_digits(x)\n return WORDS[x] if WORDS[x]\n\n r, f = x.divmod(10)\n f.zero? ? \"#{WORDS[r*10]}\" : \"#{WORDS[r*10]} #{WORDS[f]}\"\n end\n end\n end\nend\nInteger.include NumberToRupees::Integer\n"}} {"repo": "mediavrog/cfe", "pr_number": 1, "title": "update to mootools 1.3", "state": "closed", "merged_at": null, "additions": 83, "deletions": 68, "files_changed": ["cfe/addons/cfe.addon.dependencies.js", "cfe/addons/cfe.addon.toolTips.js", "cfe/base/cfe.base.js", "cfe/modules/button/cfe.module.button.js", "cfe/modules/check/cfe.module.checkbox.js", "cfe/modules/check/cfe.module.radio.js", "cfe/modules/file/cfe.module.file.js", "cfe/modules/select/cfe.module.select.js", "cfe/modules/select/cfe.module.select.multiple.js", "cfe/replace/cfe.replace.js", "demo.html"], "files_before": {"cfe/modules/file/cfe.module.file.js": "/**\n * @module File\n */\n\n/**\n * replaces file upload fields\n *\n *

is not resetted onReset

\n * \n *
Tested in:
\n *
    \n *
  • Safari 4 - implicitly labelled triggers when deletin a file; reset doesnt trigger
  • \n *
  • Firefox 3.6.
  • \n *
  • Google Chrome 6 - implicitly labelled triggers twice, when using alias button & triggers when deletin a file.
  • \n *
  • Opera 10.62.
  • \n *
  • IE 7 - gaga.
  • \n *
  • IE 8 - implicitly labelled triggers when deletin a file.
  • \n *
\n *\n * @class File\n * @namespace cfe.modules\n *\n * @extends cfe.module.Button\n */\n\ncfe.module.File = new Class({\n \n Extends: cfe.module.Button,\n \n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=file]\",\n\t\n options: {\n /**\n * enables the use of fileicons through a bit of markup and css\n * @config fileIcons\n * @type boolean\n * @default true\n */\n fileIcons: true,\n /**\n * show only the filename, not the whole path\n * @config trimFilePath\n * @type boolean\n * @default true\n */\n trimFilePath: true,\n\n innerLabel: \"Choose File\"\n },\n\n hideOriginalElement: false,\n\n toElement: function()\n {\n return this.wrapa\n },\n\n /**\n * retreive the filepath\n *\n * @method getFilePath\n * @return {HTMLElement}\n */\n getFilePath: function()\n {\n return this.v;\n },\n\n afterInitialize: function()\n {\n this.a = this.button;\n \n if(this.hideOriginalElement) this.o.hideInPlace();\n\n if(this.o.id) this.wrapa.addClass(cfe.prefix+this.type+this.o.id.capitalize());\n\n // various additions\n if(!this.o.implicitLabel && !Browser.Engine.webkit) this.wrapa.addEvent(\"click\", this.clicked.bindWithEvent(this));\n\n if(this.isDisabled()) this.disable();\n\n if(!this.options.slidingDoors) this.wrapa.addClass(cfe.prefix+this.type)\n\n if(this.options.buttonStyle) this.a.addClass(cfe.prefix+\"Button\")\n\n this.a.removeClass(cfe.prefix+this.type)\n },\n\n build: function()\n {\n this.parent();\n this.innerlabel.set(\"text\", $pick(this.options.innerLabel, \"\"));\n\n // make original element follow mouse\n // setup wrapper\n this.wrapa = new Element(\"span\",{\n \"class\": cfe.prefix+this.type,\n styles:\n {\n overflow: \"hidden\",\n position: \"relative\"\n }\n }).cloneEvents(this.a)\n \n this.wrapa.inject(this.a, \"after\").adopt(this.a, this.o);\n\n // add positioning styles and events to \"hidden\" file input\n this.o.addEvents({\n \"mouseout\": this.update.bind(this),\n \"change\": this.update.bind(this),\n onDisable: this.disable.bind(this),\n onEnable: this.enable.bind(this)\n }).setStyles({\n opacity: \"0\",\n visibility: \"visible\",\n height: \"100%\",\n width: \"auto\",\n position: \"absolute\",\n top: 0,\n right: 0,\n margin: 0\n });\n\n this.wrapa.addEvent(\"mousemove\", this.follow.bindWithEvent(this));\n\n this.button = this.a;\n this.a = this.wrapa;\n \n // add filepath\n this.v = new Element(\"span\").addClass(cfe.prefix+this.type+\"Path hidden\");\n\t\t\n this.path = new Element(\"span\").addClass(\"filePath\");\n\n if(this.options.fileIcons)\n {\n this.path.addClass(\"fileIcon\");\n }\n\n this.cross = $( new cfe.module.Button({delegateClick: false}).addEvent(\"click\", this.deleteCurrentFile.bind(this)) ).addClass(\"delete\");\n\n this.v.adopt(this.path, this.cross).inject(this.wrapa, \"after\");\n\n this.update();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"file\"\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n type: \"file\"\n });\n },\n\t\n follow: function(ev)\n {\n this.o.setStyle(\"left\",(ev.client.x-this.a.getLeft()-(this.o.getWidth()-30)));\n\t\t\n /* special treatment for internet explorer as the fileinput will not be cut off by overflow:hidden */\n if(Browser.Engine.trident){\n if(ev.client.x < this.a.getLeft() || ev.client.x > this.a.getLeft()+this.a.getWidth())\n this.o.setStyle(\"left\", -9999);\n }\n },\n\t\n update: function()\n {\n // only do stuff if original element is not disabled\n if( !$chk(this.o.disabled) )\n {\n if( this.o.value != \"\" )\n {\n this.o.disable().blur();\n\n this.oldValue = this.o.getProperty(\"value\");\n if(this.options.trimFilePath) this.oldValue = this.oldValue.trimFilePath();\n this.path.set(\"html\", this.oldValue);\n\n if(this.options.fileIcons)\n {\n var ind = this.oldValue.lastIndexOf(\".\");\n this.path.setProperty(\"class\",\"filePath fileIcon \" + this.oldValue.substring(++ind).toLowerCase());\n }\n this.v.removeClass(\"hidden\");\n }\n else\n {\n this.o.enable().focus();\n\n this.path.set(\"html\", \"\");\n this.v.addClass(\"hidden\");\n }\n\n this.parent();\n }\n },\n\t\n deleteCurrentFile: function()\n {\n // we dont clone the old file input here, since the attribute \"value\" would be cloned, too\n // and we cannot modify the value of an file input field without user interaction\n this.o = this.createOriginal().addClass(this.o.getProperty(\"class\")).setProperties({\n name: this.o.getProperty(\"name\"),\n id: this.o.getProperty(\"id\"),\n style: this.o.getProperty(\"style\"),\n title: this.o.getProperty(\"title\")\n }).cloneEvents(this.o).replaces(this.o);\n\t\t\n this.update();\n }\n});\n\n// add trimFilePath to Native String for convenience\nString.implement({\n trimFilePath: function()\n {\n var ind = false;\n if(!(ind = this.lastIndexOf(\"\\\\\")))\n if(!(ind = this.lastIndexOf(\"\\/\")))\n ind = 0;\n\n return this.substring(++ind);\n }\n});", "cfe/base/cfe.base.js": "/**\n * The core of custom form elements. Includes cfe.Generic and some slight addons to the native Element object. \n *\n * @module Core\n * @namespace cfe\n */\n\nvar cfe = {\n version: \"0.9.9\",\n prefix: \"cfe\",\n module: {},\n addon: {}\n};\n\n/**\n * extend Elements with some Helper functions\n * @class Helpers\n * @namespace Element\n */\nElement.Helpers = new Class({\n\n /**\n * cross-browser method for disabling the text selection by setting css attributes\n * \n * @method disableTextSelection\n */\n disableTextSelection: function(){\n if(Browser.Engine.trident || Browser.Engine.presto){\n this.setProperty(\"unselectable\",\"on\");\n }\n else if(Browser.Engine.gecko){\n this.setStyle(\"MozUserSelect\",\"none\");\n }\n else if(Browser.Engine.webkit){\n this.setStyle(\"KhtmlUserSelect\",\"none\");\n }\n\n return this;\n },\n\n /**\n * disables a HTMLElement if its a form element by setting the disabled attribute to true\n *\n * @method disable\n * @return boolean true, if element could be disabled\n */\n disable: function()\n {\n if($type(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", true);\n this.fireEvent(\"onDisable\");\n }\n\n return this;\n },\n\n /**\n * enables a HTMLElement if its a form element by setting the disabled attribute to false\n *\n * @method enable\n * @return {boolean} true, if element could be enabled\n */\n enable: function()\n {\n if($type(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", false);\n this.fireEvent(\"onEnable\");\n }\n\n return this;\n },\n\n /**\n * enables or disabled a HTMLElement if its a form element depending on it's current state\n *\n * @method toggleDisabled\n * @return {boolean} true, if element could be toggled\n */\n toggleDisabled: function()\n {\n if($type(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", !this.getProperty(\"disabled\") );\n this.fireEvent(this.getProperty(\"disabled\")?\"onDisable\":\"onEnable\");\n }\n return this;\n },\n\n /**\n * returns the label-element which belongs to this element\n *\n * @method getLabel\n * @return HTMLElement or NULL\n */\n getLabel: function()\n {\n var label = null;\n\n // get label by id/for-combo\n if(this.id) label = $$(\"label[for=\"+this.id+\"]\")[0];\n \n // no label was found for id/for, let's see if it's implicitly labelled\n if(!label)\n {\n label = this.getParent('label');\n\n if(label) this.implicitLabel = true;\n }\n\n return label;\n },\n\n /**\n * generates the markup used by sliding doors css technique to use with this element\n *\n * @method setSlidingDoors\n *\n * @param count\n * @param type\n * @param prefix\n * \n * @return HTMLElement or NULL the wrapped HTMLElement\n */\n setSlidingDoors: function(count, type, prefix, suffixes)\n {\n var slide = null;\n var wrapped = this;\n prefix = $pick(prefix, \"sd\");\n\n suffixes = $pick(suffixes, []);\n\n for(var i = count; i > 0; --i)\n {\n wrapped.addClass( prefix+\"Slide\"+( (i == 1 && count == i) ? \"\" : (suffixes[i] || i) ));\n slide = new Element(type);\n try{\n wrapped = slide.wraps(wrapped);\n }catch(e){\n wrapped = slide.grab(wrapped);\n }\n }\n\n wrapped = null;\n\n return slide;\n },\n\n /**\n * hide an element but keep it's vertical position and leave it tab- & screenreader-able :)\n *\n * @method hideInPlace\n *\n * @return HTMLElement\n */\n hideInPlace: function()\n {\n return this.setStyles({\n position: \"absolute\",\n left: -99999,\n width: 1,\n height: 1\n });\n }\n});\n\nElement.implement(new Element.Helpers);", "cfe/modules/check/cfe.module.radio.js": "/**\n * @module Checkable\n */\n\n/**\n *

replaces radiobuttons

\n *\n *
Tested in:
\n *
    \n *
  • Safari 4.
  • \n *
  • Firefox 3.6.
  • \n *
  • Google Chrome 6.
  • \n *
  • Opera 10.62.
  • \n *
  • IE 7.
  • \n *\n *
  • IE 8\n *
      \n *
    • labels dont work for normal labelled elements
    • \n *
    \n *
  • \n *\n *
\n *\n * @class Radiobutton\n * @namespace cfe.module\n *\n * @extends cfe.modules.Checkbox\n */\ncfe.module.Radiobutton = new Class({\n\n Extends: cfe.module.Checkbox,\n\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=radio]\",\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"radio\"\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n \"type\": \"radio\",\n \"checked\": this.options.checked\n });\n },\n\n /**\n * @method initializeAdv\n * @protected\n */\n afterInitialize: function()\n {\n this.parent();\n \n if( !(Browser.Engine.trident || Browser.Engine.gecko) ) this.o.addEvent(\"click\", this.update.bind(this));\n\n // on check, disable all other radiobuttons in this group\n this.addEvent(\"check\", function(){\n $$(\"input[name='\"+this.o.get(\"name\")+\"']\").each(function(el)\n {\n if(el != this.o && el.retrieve(\"cfe\")) el.retrieve(\"cfe\").uncheck();\n }.bind(this));\n })\n }\n});", "cfe/replace/cfe.replace.js": "/**\n * replacement class for automated replacment of scoped form elements\n *\n * @module replace\n * @namespace cfe\n *\n */\n\ncfe.Replace = new Class(\n{\n Implements: [new Options, new Events],\n\n options:{\n scope: false,\n\t\t\n onInit: $empty,\n onInitSingle: $empty,\n onBeforeInitSingle: $empty,\n onSetModuleOption: $empty,\n onRegisterModule: $empty,\n onUnregisterModule: $empty,\n onComplete: $empty\n },\n\t\t\n modules: {},\n moduleOptions: {},\n moduleOptionsAll: {},\n\t\n initialize: function()\n {\n this.registerAllModules.bind(this)();\n },\n\t\n /**\n * @method registerAllModules\n\t * registeres all loaded modules onInitialize\n\t */\n registerAllModules: function(){\n\t\t\n //console.log(\"Register all modules\");\n\t\t\n $each(cfe.module, function(modObj, modType){\n //console.log(\"Registering type \"+modType);\n if(modType != \"Generic\")\n this.registerModule(modType);\n\t\t\t\t\n }.bind(this));\n },\n\t\n /* call to register module */\n registerModule: function(mod){\n\t\t\n //console.log(\"Call to registerModule with arg:\"+mod);\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onRegisterModule\", [mod,modObj]);\n this.modules[mod] = modObj;\n this.moduleOptions[mod] = {};\n\n return true;\n },\n\t\n registerModules: function(mods)\n {\n $each(mods,function(mod){\n this.registerModule(mod);\n },this);\n },\n\t\n unregisterModule: function(mod)\n {\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onUnregisterModule\", [mod,modObj]);\n\n delete this.modules[mod];\n },\n\t\n unregisterModules: function(mods)\n {\n $each(mods,function(mod){\n this.unregisterModule(mod);\n },this);\n },\n /**\n\t * sets a single option for a specified module\n\t * if no module was given, it sets the options for all modules\n\t *\n * @method setModuleOption\n *\n\t * @param {String} \tmod \tName of the module\n\t * @param {String} \topt \tName of the option\n\t * @param {Mixed} \tval\t\tThe options value\n\t */\n setModuleOption: function(mod,opt,val){\n\t\t\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onSetModuleOption\", [mod,modObj,opt,val]);\n\t\t\n if(!modObj){\n this.moduleOptionsAll[opt] = val;\n }\n else{\n this.moduleOptions[mod][opt] = val;\n }\n },\n\n setModuleOptions: function(mod,opt){\n\t\t\n $each(opt, function(optionValue, optionName){\n this.setModuleOption(mod,optionName,optionValue);\n }.bind(this));\n\t\t\n },\n\n engage: function(options){\n\n this.setOptions(this.options, options);\n\n if($type(this.options.scope) != \"element\"){\n this.options.scope = $(document.body);\n }\n\n this.fireEvent(\"onInit\");\n\t\t\n $each(this.modules,function(module,moduleName,i){\n\t\t\t\n var selector = module.prototype.selector;\n\t\t\t\n this.options.scope.getElements(selector).each(function(el,i){\n\n if(el.retrieve(\"cfe\") != null){\n\n var basicOptions = {\n replaces: el\n };\n\n this.fireEvent(\"onBeforeInitSingle\", [el,i,basicOptions]);\n\n var single = new module($merge(basicOptions,$merge(this.moduleOptions[moduleName],this.moduleOptionsAll)));\n\t\t\t\t\n this.fireEvent(\"onInitSingle\", single);\n }else{\n this.fireEvent(\"onSkippedInitSingle\", [el,i,basicOptions]); \n }\n\t\t\t\t\n },this);\n },this);\n\t\t\n this.fireEvent(\"onComplete\");\n }\n});", "cfe/modules/check/cfe.module.checkbox.js": "/**\n * @module Checkable\n */\n\n/**\n *

replaces checkboxes

\n * \n *
Tested in:
\n *
    \n *
  • Safari 4.
  • \n *
  • Firefox 3.6.
  • \n *
  • Google Chrome 6.
  • \n *
  • Opera 10.62.
  • \n *
  • IE 7.
  • \n *
  • IE 8.
  • \n *
\n *\n * @class Checkbox\n * @namespace cfe.module\n * \n * @extends cfe.module.Button\n */\ncfe.module.Checkbox = new Class({\n \n Extends: cfe.module.Button,\n \n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=checkbox]\",\n\n options:{\n /**\n * @inherit\n */\n slidingDoors: false\n /**\n * Fired when the original element gets checked\n * @event onCheck\n */\n //onCheck: Class.empty,\n /**\n * Fired when the original element's checked state is set to false\n * @event onUnCheck\n */\n //onUncheck: Class.empty\n },\n\n afterInitialize: function()\n {\n this.parent();\n\n // important for resetting dynamically created cfe\n this.o.defaultChecked = this.o.checked;\n\n if( Browser.Engine.presto || Browser.Engine.trident )\n {\n //console.log(\"fix for element update (IE and Opera)\")\n this.o.addEvent(\"click\", this.update.bind(this) );\n }\n\n\n if(Browser.Engine.trident && this.o.implicitLabel)\n {\n //console.log(\"fix for implicit labels (IE) element[\"+this.o.id+\"]\")\n this.l.removeEvents(\"click\")\n this.a.removeEvents(\"click\").addEvent(\"click\", function(e){\n e.stop();\n this.clicked.bind(this)();\n }.bind(this))\n }\n\n this.update();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"checkbox\"\n * @protected\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n type: \"checkbox\",\n checked: this.options.checked\n });\n },\n\n clicked: function(e)\n {\n if(Browser.Engine.trident && e) e.stop();\n\n this.parent()\n },\n\n /**\n * public method to check a checkbox programatically\n *\n * @method check\n * @public\n */\n check: function()\n {\n this.a.addClass(\"A\");\n this.fireEvent(\"onCheck\");\n },\n\n /**\n * public method to uncheck a checkbox programatically\n *\n * @method uncheck\n * @public\n */\n uncheck: function()\n {\n this.a.removeClass(\"A\");\n this.fireEvent(\"onUncheck\");\n },\n\n update: function()\n {\n this.o.checked ? this.check() : this.uncheck();\n this.parent();\n }\n});", "cfe/addons/cfe.addon.toolTips.js": "/**\n * @module Addon\n */\n\n/**\n * pretty simple integration of auto-generated tooltips (from title-attribute)\n * depends on mootools Tips\n *\n * @class Tips\n * @namespace cfe.addon\n *\n */\ncfe.addon.Tips = new Class({\n\t\n options: $merge(this.parent, {\n enableTips: true,\n ttStyle: \"label\",\n ttClass: cfe.prefix+\"Tip\"\n }),\n\t\n initToolTips: function(){\n\t\t\n if(!window.Tips || !this.options.enableTips){\n if(this.options.debug){\n this.throwMsg.bind(this)(\"CustomFormElements: initialization of toolTips failed.\\nReason: Mootools Plugin 'Tips' not available.\");\n }\n \n return false;\n }\n\t\n switch(this.options.ttStyle){\n default:case 'label': this.toolTipsLabel.bind(this)();break;\n }\n\n return true;\n },\n\t\n toolTipsLabel: function(){\n\t\t\n var labels = this.options.scope.getElements('label');\n \t\t\n labels.each(function(lbl,i){\n\n forEl = lbl.getProperty(\"for\");\n\t\t\t\n if(!forEl){\n var cl = lbl.getProperty(\"class\");\n\t\t\t\t\n if( $defined(cl) ){\n var forEl = cl.match(/for_[a-zA-Z0-9\\-]+/);\n\n if(forEl){\n forEl = forEl.toString();\n el = $( forEl.replace(/for_/,\"\") );\n } \n }\n\t\t\t\t\n if(!el){\n el = lbl.getElement(\"input\");\n }\n }else{\n el = $(forEl);\n }\n\n if(el){\n if($chk(qmTitle = el.getProperty(\"title\"))){\n\t\t\t\t\t\n el.setProperty(\"title\",\"\").setProperty(\"hint\", qmTitle)\n\t\t\t\t\t\n var qm = new Element(\"span\",{\n \"class\": this.options.ttClass,\n \"title\": qmTitle\n });\n \n // check if implicit label span is present\n var impLabel = lbl.getFirst(\"span[class=label]\");\n \n qm.injectInside($chk(impLabel)?impLabel:lbl);\n }\n }\n },this);\n\t\t\n new Tips($$('.'+this.options.ttClass+'[title]'));\n }\n});\n\ncfe.Replace.implement(new cfe.addon.Tips);\ncfe.Replace.prototype.addEvent(\"onComplete\", function(){\n this.initToolTips();\n});", "cfe/addons/cfe.addon.dependencies.js": "/**\n * @module Addon\n */\n\n/**\n * adds dependencies to checkboxes\n *\n * @class Dependencies\n * @namespace cfe.addon\n *\n */\ncfe.addon.Dependencies = new Class({\n\t\n /**\n\t * adds dependencies for an element \n\t * @param {Object} el\n\t * @param {Array} dep\n\t */\n addDependencies: function(el, deps){\n $each(deps,function(dep){\n this.addDependency(el,dep);\n }.bind(this));\n },\n\t\n /**\n\t * adds dependency for an element \n\t * @param {Object} el\n\t * @param {Object} dep\n\t */\n addDependency: function(el, dep){\n\t\t\n // create an array if needed\n if($type( el.retrieve('deps') ) !== \"array\"){\n el.store('deps', []);\n }\n\t\t\n // deps may be objects or strings > if a string was given, try to interpret it as id and fetch element by $()\n if($type(dep) === \"string\" || $type(dep) === \"element\"){\n el.retrieve('deps').push( $(dep) );\n return true;\n }\n\t\t\n return false;\n },\n\t\n getDependencies: function(el)\n {\n return el.retrieve('deps');\n },\n\t\n /**\n\t * this is called when a new item of a cfemodule gets initialized\n\t * it checks, whether there are dependencies for this element and adds them to its options\n\t * \n\t * @param {Object} el\n\t */\n attachDependencies: function(el,i,baseOptions)\n {\n var deps = this.getDependencies(el);\n\t\t\n if($type(deps) === \"array\"){\n baseOptions.deps = deps;\n return true;\n }\n\t\n return false;\n }\n\t\t\n});\ncfe.Replace.implement(new cfe.addon.Dependencies);\ncfe.Replace.prototype.addEvent(\"onBeforeInitSingle\", cfe.Replace.prototype.attachDependencies);\n\ncfe.addon.Dependencies.Helper = new Class({\n resolveDependencies: function()\n {\n var deps = this.o.retrieve('deps');\n\t\t\n if(deps){\n $each(deps, function(dep,i){\n dep.checked = true;\n dep.fireEvent(\"change\");\n }.bind(this));\n }\n }\n});\n\n// support for checkboxes\ncfe.module.Checkbox.implement(new cfe.addon.Dependencies.Helper);\ncfe.module.Checkbox.prototype.addEvent(\"onCheck\", function(){\n this.resolveDependencies();\n});", "cfe/modules/button/cfe.module.button.js": "/**\n * @module Button\n */\n\n/**\n * gets extended by modules to start off with standard, button-like behaviours.\n *\n * when focused and pressed, form gets submitted\n *\n * @class Button\n * @namespace cfe.module\n *\n */\ncfe.module.Button = new Class(\n{\n Implements: [new Options, new Events],\n\n selector: \"button\",\n\n instance: 0,\n\n /**\n * basic options for all cfes and always available\n * @property options\n */\n options: {\n /**\n * if > 0, it will create markup for css sliding doors tech
\n * the number defines the amount of wrappers to create around this element
\n * 2: standard sliding doors (x- or y-Axis)
\n * 4: sliding doors in all directions (x/y-Axis)\n *\n * @config slidingDoors\n * @type int\n * @default 4\n */\n slidingDoors: 2,\n\n /**\n * if this element shall replace an existing html form element, pass it here\n * @config replaces\n * @type HTMLElement\n */\n replaces: null,\n\n /**\n * determines if a click on the decorator should be delegated to the original element\n * @config delegateClick\n * @type Boolean\n */\n delegateClick: true,\n\n /**\n * may pass any element as a label (toggling, hovering,..) for this cfe\n * @config label\n * @type HTMLElement\n */\n label: null,\n\n /**\n * if this cfe is created programatically, it's possible to set the name attribute of the generated input element\n * @config name\n * @type string\n */\n name: \"\",\n\n /**\n * setting this to true will create a disabled element\n * @config disabled\n * @type boolean\n */\n disabled: false,\n\n buttonStyle: true\n\n /**\n * Fired when the mouse is moved over the \"decorator\" element\n * @event onMouseOver\n */\n //onMouseOver: Class.empty,\n\n /**\n * Fired when the mouse is moved away from the \"decorator\" element\n * @event onMouseOut\n */\n //onMouseOut: Class.empty,\n\n /**\n * Fired when the \"original\" element gets focus (e.g. by tabbing)\n * @event onFocus\n */\n //onFocus: Class.empty,\n\n /**\n * Fired when the \"original\" element loses focus\n * @event onBlur\n */\n //onBlur: Class.empty,\n\n /**\n * Fired when \"decorator\" is clicked by mouse\n * @event onClick\n */\n //onClick: Class.empty,\n\n /**\n * Fired when pressing down with the mouse button on the \"decorator\"\n * Fired when pressing the space key while \"original\" has focus\n * @event onPress\n */\n //onPress: Class.empty,\n\n /**\n * Fired when \"decorator\" was pressed and the mouse button is released\n * Fired when \"original\" was pressed by space key and this key is released\n * @event onRelease\n */\n //onRelease: Class.empty,\n\n /**\n * Fired when \"original\"'s value changes\n * @event onUpdate\n */\n //onUpdate: Class.empty,\n\n /**\n * Fired when \"original\" gets disabled by HTMLElement.enable()\n * @event onEnable\n */\n //onEnable: Class.empty,\n\n /**\n * Fired when \"original\" gets disabled by HTMLElement.disable()\n * @event onDisable\n */\n //onDisable: Class.empty,\n\n /**\n * Fired when decorator is completely loaded and is ready to use\n * @event onLoad\n */\n //onLoad: Class.empty\n\n\n },\n\n hideOriginalElement: true,\n\n /**\n * constructor
\n * building algorithm for cfe (template method)
\n *
    \n *
  1. setOptions: set Options
  2. \n *
  3. buildWrapper: setup the \"decorator\"
  4. \n *
  5. setupOriginal: procede the \"original\" element (add Events...)
  6. \n *
  7. addLabel: add and procede the label
  8. \n *
  9. initializeAdv: last chance for subclasses to do initialization
  10. \n *
  11. build: various specific dom handling and \"decorator\" building
  12. \n *\n * @method initialize\n * @constructor\n *\n * @param {Object} options\n **/\n initialize: function(opt)\n {\n // sets instance id\n this.instance = this.constructor.prototype.instance++;\n\n this.setOptions(opt);\n\n this.type = $pick(this.options.type, $H(cfe.module).keyOf(this.constructor));\n\n this.buildWrapper();\n\n // prepares original html element for use with cfe and injects decorator into dom\n this.setupOriginal();\n\n // add a label, if present\n this.addLabel( $pick(this.o.getLabel(), this.setupLabel(this.options.label) ) );\n\n this.build();\n\n // add events to wrapping element\n this.setupWrapperEvents();\n\n // specific initialization\n this.afterInitialize();\n\n this.fireEvent(\"load\")\n },\n\n /**\n * retreive the \"decorator\"\n * mootools supports the use of $(myCfe) if toElement is defined\n *\n * @method toElement\n * @return {HTMLElement}\n */\n toElement: function()\n {\n return this.a;\n },\n\n /**\n * retreive the label\n *\n * @method getLabel\n * @return {HTMLElement}\n */\n getLabel: function()\n {\n return this.l;\n },\n\n /**\n * template method STEP 1\n */\n buildWrapper: function(){\n this.a = new Element(\"span\");\n },\n\n /**\n * handles the creation of the underlying original form element
    \n * stores a reference to the cfe object in the original form element\n * template method STEP 2\n *\n * @method setupOriginal\n * @protected\n */\n setupOriginal: function()\n {\n // get original element\n if( $defined(this.options.replaces) )\n {\n this.o = this.options.replaces;\n this.a.inject(this.o, 'before');\n }\n else // standalone\n {\n this.o = this.createOriginal();\n\n if(this.options.id) this.o.setProperty(\"id\", this.options.id);\n\n if(this.options.disabled) this.o.disable();\n\n if(this.options.name)\n {\n this.o.setProperty(\"name\", this.options.name);\n\n if( !$chk(this.o.id) ) this.o.setProperty(\"id\", this.options.name+this.instance);\n }\n\n if(this.options.value) this.o.setProperty(\"value\", this.options.value);\n\n this.a.adopt(this.o);\n }\n\n this.o.addEvents({\n focus: this.setFocus.bind(this),\n blur: this.removeFocus.bind(this),\n change: this.update.bind(this),\n keydown: function(e){\n if(e.key == \"space\") this.press();\n }.bind(this),\n keyup: function(e){\n if(e.key == \"space\") this.release();\n }.bind(this),\n onDisable: function(){\n this.a.fireEvent(\"disable\");\n }.bind(this),\n onEnable: function(){\n this.a.fireEvent(\"enable\");\n }.bind(this)\n });\n\n // store a reference to this cfe \"in\" the original form element\n this.o.store(\"cfe\", this);\n },\n\n /*\n * adds a label element to this cfe\n * template method STEP 3\n *\n * @method addLabel\n * @protected\n *\n * @param {HTMLElement} the label element to set as label for this cfe\n */\n addLabel: function(label)\n {\n if( !$defined(label) ) return;\n\n this.l = label;\n\n // remove for property\n if(!this.dontRemoveForFromLabel) this.l.removeProperty(\"for\");\n\n // add adequate className, add stdEvents\n this.l.addClass(cfe.prefix+this.type+\"L\");\n\n if(this.o.id || this.o.name) this.l.addClass(\"for_\"+ (this.o.id || (this.o.name+this.o.value).replace(\"]\",\"-\").replace(\"[\",\"\") ));\n\n // add stdevents\n this.l.addEvents({\n mouseover: this.hover.bind(this),\n mouseout: this.unhover.bind(this),\n mousedown: this.press.bind(this),\n mouseup: this.release.bind(this),\n click: this.clicked.bindWithEvent(this)\n });\n\n this.addEvents({\n press: function()\n {\n this.l.addClass(\"P\");\n },\n release: function()\n {\n this.l.removeClass(\"P\");\n },\n mouseOver: function()\n {\n this.l.addClass(\"H\");\n },\n mouseOut: function()\n {\n this.l.removeClass(\"H\");\n this.l.removeClass(\"P\");\n },\n focus: function()\n {\n this.l.addClass(\"F\");\n },\n blur: function()\n {\n this.l.removeClass(\"F\");\n //this.l.removeClass(\"P\");\n },\n enable: function()\n {\n this.l.removeClass(\"D\");\n },\n disable: function()\n {\n this.l.addClass(\"D\");\n }\n });\n },\n\n /**\n * part of the main template method for building the \"decorator\"
    \n * must be extended by subclasses\n *\n * template method STEP 4\n *\n * @method build\n * @protected\n */\n build: function(){\n\n this.innerlabel = this.setupInnerLabel();\n this.a.adopt(this.innerlabel);\n\n if( $chk(this.options.slidingDoors) )\n {\n this.a = this.a.setSlidingDoors(this.options.slidingDoors-1, \"span\", cfe.prefix).addClass(cfe.prefix+this.type);\n }\n },\n\n\n /**\n * adds events and mousepointer style to the \"decorator\"\n * usually gets called by buildWrapper\n *\n * template method STEP 5\n *\n * @method setupWrapperEvents\n * @protected\n */\n setupWrapperEvents: function()\n {\n if(!this.o.implicitLabel)\n {\n this.a.addEvents({\n mouseover: this.hover.bind(this),\n mouseout: this.unhover.bind(this),\n mousedown: this.press.bind(this),\n mouseup: this.release.bind(this)\n });\n }\n\n this.a.addEvents({\n disable: this.disable.bind(this),\n enable: this.enable.bind(this)\n })\n \n },\n\n /**\n * part of the main template method for building the \"decorator\"
    \n * gets called immediately before the build-method
    \n * may be extended by subclasses\n *\n * template method STEP 6\n *\n * @method initializeAdv\n * @protected\n */\n afterInitialize: function()\n {\n if(this.hideOriginalElement) this.o.hideInPlace();\n\n if(this.o.id) this.a.addClass(cfe.prefix+this.type+this.o.id.capitalize());\n\n // various additions\n if(!this.o.implicitLabel) this.a.addEvent(\"click\", this.clicked.bindWithEvent(this));\n\n if(this.isDisabled()) this.a.fireEvent(\"disable\");\n\n if(!this.options.slidingDoors) this.a.addClass(cfe.prefix+this.type)\n\n if(this.options.buttonStyle) this.a.addClass(cfe.prefix+\"Button\")\n },\n\n setupInnerLabel: function(){\n return new Element(\"span\").addClass(\"label\").disableTextSelection();\n },\n\n\n /**\n * getter for retrieving the disabled state of the \"original\" element\n *\n * @method isDisabled\n * @return boolean\n */\n isDisabled: function()\n {\n return this.o.getProperty(\"disabled\")\n },\n\n /**\n * programatically creates an \"original\" element
    \n * each subclass has to implement this\n *\n * @method createOriginal\n * @return {HTMLElement}\n */\n createOriginal: function()\n {\n return new Element(\"button\")\n },\n\n /*\n * creates a label element and fills it with the contents (may be html) given by option \"label\"\n *\n * @method setupLabel\n * @protected\n *\n * @return {HTMLElement or NULL} if option \"label\" is not set\n */\n setupLabel: function()\n {\n if( $defined(this.options.label) ) return new Element(\"label\").set(\"html\", this.options.label).setProperty(\"for\", this.o.id);\n\n return null;\n },\n\n /**\n * wrapper method for event onPress
    \n * may be extended by subclasses\n *\n * @method press\n * @protected\n */\n press: function()\n {\n if(this.isDisabled()) return\n\n this.a.addClass(\"P\");\n this.fireEvent(\"onPress\");\n\n //console.log(this.type + \"pressed\");\n },\n\n /**\n * wrapper method for event onRelease
    \n * may be extended by subclasses\n *\n * @method release\n * @protected\n */\n release: function()\n {\n if(this.isDisabled()) return\n\n this.a.removeClass(\"P\");\n this.fireEvent(\"onRelease\");\n \n //console.log(this.type + \"released\");\n\n },\n\n /**\n * wrapper method for event onMouseOver
    \n * may be extended by subclasses\n *\n * @method onMouseOver\n * @protected\n */\n hover: function()\n {\n if(this.isDisabled()) return\n\n this.a.addClass(\"H\");\n this.fireEvent(\"onMouseOver\");\n\n //console.log(this.type + \"hovered\");\n },\n\n /**\n * wrapper method for event onMouseOut
    \n * may be extended by subclasses\n *\n * @method unhover\n * @protected\n */\n unhover: function()\n {\n if(this.isDisabled()) return\n\n this.a.removeClass(\"H\");\n this.fireEvent(\"onMouseOut\");\n this.release();\n\n //console.log(this.type + \"unhovered\");\n },\n\n /**\n * wrapper method for event onFocus
    \n * may be extended by subclasses\n *\n * @method setFocus\n * @protected\n */\n setFocus: function()\n {\n this.a.addClass(\"F\");\n this.fireEvent(\"onFocus\");\n\n //console.log(this.type + \"focused\");\n },\n\n /**\n * wrapper method for event onBlur
    \n * may be extended by subclasses\n *\n * @method removeFocus\n * @protected\n */\n removeFocus: function()\n {\n //console.log(\"o blurred\");\n this.a.removeClass(\"F\");\n // if cfe gets blurred, also clear press state\n //this.a.removeClass(\"P\");\n this.fireEvent(\"onBlur\");\n\n //console.log(this.type + \"blurred\");\n\n },\n\n /**\n * wrapper method for event onClick
    \n * delegates the click to the \"original\" element
    \n * may be extended by subclasses\n *\n * @method clicked\n * @protected\n */\n clicked: function(e)\n {\n //causes problems in other browsers than ie - gonna took into this later; its the best approach to stop the event from bubbling right here though imho\n //e.stop();\n\n if(this.isDisabled()) return\n\n if( $chk(this.o.click) && $chk(this.options.delegateClick) ) this.o.click();\n this.o.focus();\n\n this.fireEvent(\"onClick\");\n\n //console.log(this.type + \" clicked\");\n },\n\n /**\n * wrapper method for event onUpdate
    \n * may be extended by subclasses\n *\n * @method update\n * @protected\n */\n update: function()\n {\n this.fireEvent(\"onUpdate\");\n\n //console.log(\"o was updated\");\n },\n\n /**\n * wrapper method for event onEnable
    \n * may be extended by subclasses\n *\n * @method enable\n * @protected\n */\n enable: function()\n {\n this.a.removeClass(\"D\");\n this.fireEvent(\"onEnable\");\n\n //console.log(this.type+\"-\"+this.instance+\" now enabled\");\n },\n\n /**\n * wrapper method for event onDisable
    \n * may be extended by subclasses\n *\n * @method disable\n * @protected\n */\n disable: function()\n {\n this.a.addClass(\"D\");\n this.fireEvent(\"onDisable\");\n\n //console.log(this.type+\"-\"+this.instance+\" now disabled\");\n }\n});", "cfe/modules/select/cfe.module.select.js": "/**\n * @module Scrollable\n */\n\n/**\n * SCROLLING functionality for select boxes;\n * TODO: refactor to standalone module\n * \n * creates handles and sets up a slider object\n *\n * @class Scrollable\n * @namespace cfe.helper\n *\n * \n */\ncfe.helper = cfe.helper || {}\n\ncfe.helper.Scrollable = {\n\n options: {\n size: 4,\n scrolling: true\n },\n \n setupScrolling: function()\n {\n // slider config\n this.scrollerWrapper = new Element(\"span\",{\n \"class\": cfe.prefix+\"ScrollerWrapper\",\n \"styles\":{\n height: this.container.getHeight()\n }\n }).inject(this.container, \"after\");\n\n var scrollTimer, scrollTimeout;\n var scrollStepHeight = this.allOptions[0].getHeight();\n\n function scroll(by){\n clearInterval(scrollTimer);\n clearTimeout(scrollTimeout);\n\n slider.set(slider.step+by);\n\n scrollTimeout = (function(){\n scrollTimer = (function(){\n slider.set(slider.step+by);\n }.bind(this)).periodical(50)\n }.bind(this)).delay(200)\n }\n\n function clearScroll(){\n clearInterval(scrollTimer);\n clearTimeout(scrollTimeout);\n }\n\n this.scrollerTop = $(new cfe.module.Button({\n delegateClick: false\n }).addEvent(\"release\", clearScroll).addEvent(\"press\", scroll.pass(-1))).addClass(\"scrollTop\");\n\n this.scrollerBottom = $(new cfe.module.Button({\n delegateClick: false\n }).addEvent(\"release\", clearScroll).addEvent(\"press\", scroll.pass(1))).addClass(\"scrollBottom\")\n\n this.scrollerKnob = new Element(\"span\").addClass(\"scrollKnob\");\n this.scrollerBack = new Element(\"span\").addClass(\"scrollRail\");\n\n this.scrollerBack.adopt(this.scrollerKnob);\n this.scrollerWrapper.adopt(this.scrollerBack, this.scrollerTop, this.scrollerBottom);\n\n var slider = new Slider(this.scrollerBack, this.scrollerKnob, {\n steps: this.allOptions.length-this.options.size,\n mode: \"vertical\" ,\n onChange: function(step){\n this.container.scrollTo(false,step*scrollStepHeight);\n }.bind(this)\n }).set(this.selectedIndex);\n\n this.scrollerKnob.setStyle(\"position\", \"absolute\");\n\n // scrolling\n function wheelListener(ev)\n {\n ev.stop();\n slider.set(slider.step-ev.wheel);\n }\n\n this.boundWheelListener = wheelListener.bindWithEvent(this)\n\n this.addEvent(\"containerShow\", function(){\n $(document.body).addEvent(\"mousewheel\", this.boundWheelListener)\n\n slider.set(this.o.selectedIndex);\n this.container.scrollTo(false,this.o.selectedIndex*scrollStepHeight);\n })\n\n this.addEvent(\"containerHide\", function(){\n $(document.body).removeEvent(\"mousewheel\", this.boundWheelListener);\n })\n\n this.o.addEvent(\"change\", function(){\n slider.set(this.o.selectedIndex)\n }.bind(this))\n }\n}\n\n/**\n * @module Selectable\n */\n\n/**\n * replaces select fields\n *\n *

    disabled should also disable scrolling

    \n * \n *
    Tested in:
    \n *
      \n *
    • Safari 4.
    • \n *
    • Firefox 3.6.
    • \n *
    • Google Chrome 6.
    • \n *
    • Opera 10.62 - key autocompletion closes box.
    • \n *
    • IE 7.
    • \n *
    • IE 8.
    • \n *
    \n *\n * @class Select\n * @namespace cfe.module\n *\n * @extends cfe.module.Button\n *\n */\ncfe.module.Select = new Class({\n\t\n Extends: cfe.module.Button,\n Implements: cfe.helper.Scrollable,\n \n Binds: \"clickedOutsideListener\",\n\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"select:not(select[multiple])\",\n\t\n selectedIndex: 0,\n\n setupOriginal: function()\n {\n this.parent();\n \n this.o.addEvents({\n \"keyup\": this.keyup.bind(this),\n \"keydown\": this.keydown.bind(this)\n });\n },\n\n afterInitialize: function()\n {\n this.parent();\n\n // set width to widest option if no width is given to select via css\n if(this.cssWidth == \"auto\") this.a.setStyle(\"width\", this.container.getWidth())\n\n // inject labelArrow as IE 7 doesn't support :after css selector\n if(Browser.Engine.trident5) new Element(\"span\").addClass(\"labelArrow\").inject(this.innerlabel, \"after\")\n\n // select default option\n if(this.selectedIndex != -1) this.selectOption(this.selectedIndex, true);\n\n if(this.options.scrolling)\n {\n this.container.setStyle(\"height\", this.allOptions[0].getHeight()*this.options.size);\n this.setupScrolling();\n }\n\n this.hideContainer();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} a select input\n */\n createOriginal: function()\n {\n var ori = new Element(\"select\");\n\n if( $chk(this.options.options) )\n {\n for(var key in this.options.options)\n {\n ori.adopt( new Element(\"option\", {\n value: key,\n selected: this.options.options[key].selected?\"selected\":\"\"\n }).set(\"html\", this.options.options[key].label ) );\n }\n }\n return ori;\n },\n\n build: function()\n {\n this.origOptions = this.o.getChildren();\n\n this.selectedIndex = this.o.selectedIndex || this.selectedIndex;\n\n // integrity check\n if(this.options.size > this.origOptions.length || this.options.scrolling != true) this.options.size = this.origOptions.length;\n \n this.parent();\n\n this.a.setStyles({\"position\": \"relative\", \"z-index\": 100000 - this.instance});\n\n // build container which shows on click\n this.buildContainer();\n\n this.cssWidth = this.a.getStyle(\"width\");\n },\n\n buildContainer: function()\n {\n this.container = new Element(\"span\",{\n \"class\": cfe.prefix+this.type+\"Container\",\n \"styles\":{\n \"overflow\":\"hidden\"\n }\n });\n \n this.containerWrapper = this.container.setSlidingDoors(4, \"span\", cfe.prefix).addClass(cfe.prefix+this.type+\"ContainerWrapper\").setStyles({\n position: \"absolute\",\n \"z-index\": this.instance + 1\n }).inject(this.a);\n\n // insert option elements\n this.allOptions = [];\n this.origOptions.each(function(el,i)\n {\n this.allOptions.push(this.buildOption(el, i))\n }.bind(this));\n\n this.container.adopt(this.allOptions);\n\n },\n\n buildOption: function(el, i)\n {\n return new Element(\"span\",{\n \"class\": cfe.prefix+\"Option \"+cfe.prefix+\"Option\"+i+(el.get('class')?\" \"+el.get('class'):\"\"),\n \"events\":{\n \"mouseover\": this.highlightOption.pass([i,true],this)/*,\n \"mouseout\": this.highlightOption.pass([i,true],this)*/\n }\n }).set('html', el.innerHTML.replace(/\\s/g, \" \")).disableTextSelection().store(\"index\", i);\n },\n\n selectOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n this.highlightOption(index);\n\n this.selectedIndex = index;\n\n this.innerlabel.set('html', (this.allOptions[index]).innerHTML);\n\n this.fireEvent(\"onSelectOption\", index);\n },\n\n highlightOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n if(this.highlighted) this.highlighted.removeClass(\"H\");\n\n this.highlighted = this.allOptions[index].addClass(\"H\");\n\n this.highlightedIndex = index;\n\n this.fireEvent(\"onHighlightOption\", index);\n },\n\n updateOption: function(by)\n {\n // fix for IE 7\n if(this.containerWrapper.retrieve(\"hidden\") != true && !Browser.Engine.trident5) this.o.selectedIndex = (this.highlightedIndex+by).limit(0,this.origOptions.length-1);\n this.o.fireEvent(\"change\");\n },\n\n hideContainer: function()\n {\n $(document.body).removeEvent(\"click\", this.clickedOutsideListener);\n \n this.containerWrapper.setStyle(\"display\",\"none\").removeClass(\"F\").store(\"hidden\", true);\n\n this.fireEvent(\"onContainerHide\", this.selectedIndex);\n },\n\n showContainer: function()\n {\n $(document.body).addEvent(\"click\", this.clickedOutsideListener);\n\n this.containerWrapper.setStyle(\"display\", \"block\").addClass(\"F\").store(\"hidden\", false);\n\n this.highlightOption(this.o.selectedIndex);\n\n this.fireEvent(\"onContainerShow\", this.selectedIndex);\n },\n\n clicked: function(ev)\n {\n if(!this.isDisabled())\n {\n if( $defined(ev.target) )\n {\n var oTarget = $(ev.target);\n\n if( oTarget.getParent() == this.container )\n {\n this.selectOption(oTarget.retrieve(\"index\"), true);\n this.hideContainer();\n this.parent();\n this.o.selectedIndex = oTarget.retrieve(\"index\");\n this.o.fireEvent(\"change\");\n return;\n }\n else if(this.options.scrolling && oTarget.getParent(\".\"+this.scrollerWrapper.getProperty(\"class\")) == this.scrollerWrapper)\n {\n //console.log(\"no toggle\");\n return;\n }\n }\n\n this.toggle();\n this.parent();\n }\n },\n\n toggle: function()\n {\n this.containerWrapper.retrieve(\"hidden\") == true ? this.showContainer() : this.hideContainer();\n },\n\t\n keyup: function(ev)\n {\n // toggle on alt+arrow\n if(ev.alt && (ev.key == \"up\" || ev.key == \"down\") )\n {\n this.toggle();\n return;\n }\n\n switch(ev.key){\n case \"enter\":\n case \"space\":\n this.toggle();\n break;\n\n case \"up\":\n this.updateOption(-1);\n break;\n\n case \"down\":\n this.updateOption(1);\n break;\n\n case \"esc\":\n this.hideContainer();\n break;\n \n default:\n this.o.fireEvent(\"change\");\n break;\n }\n },\n\n keydown: function(ev)\n {\n if(ev.key == \"tab\")\n {\n this.hideContainer();\n }\n },\n\n clickedOutsideListener: function(ev)\n {\n if ($(ev.target).getParent(\".\"+cfe.prefix+this.type) != this.a && !( (Browser.Engine.trident || (Browser.Engine.presto && Browser.Engine.version > 950)) && ev.target == this.o) && ( !$chk(this.l) || (this.l && $(ev.target) != this.l) ) ) this.hideContainer();\n },\n\n update: function()\n {\n this.parent();\n this.selectOption(this.o.selectedIndex);\n }\n});", "demo.html": "\n\n \n \n \n\n \n \n \n \n\n \n \n

    CFE Barebone Example

    \n

    for mootools 1.2

    \n

    \n Visit homepage\n

    \n\n
    \n\n\n
    Checkboxes (input[checkbox])\n \n\n
    \n\n
    Checkboxes with implicit labelling\n

    NOTE: 3rd Checkbox has dependencies: 1st and 2nd get automatically checked if not already

    \n
      \n
    • \n
    • \n\n
    • \n
    • \n\n
    • \n\n
    \n
    \n\n\n
    Radiobuttons (input[radio])\n
      \n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n
    • \n\n
    • \n
    • \n\n\n
    • \n
    • \n\n
    • \n
    • \n
    \n
    \n\n\n
    Textinput&-area(input[text,password],textarea)- w/ slidingDoors\n
      \n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • trigger textfield 4 disabled/enabled\n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • trigger textarea 2 disabled/enabled\n
    • \n\n
    • \n \n
    • \n
    \n
    \n\n\n\n
    Textinput&-area with implicit labelling\n
      \n
    • \n
    • \n\n
    • \n
    • \n\n
    • \n
    • \n\n
    • \n\n
    • \n\n
    • \n
    • \n
    \n
    \n\n\n\n \n\n
    Selectfield (select) with and without multiple option and preselected\n
      \n\n
    • \n \n
    • \n\n
    • \n\n \n
    • \n\n
    • \n \n
    • \n\n
    • trigger select 3 disabled/enabled\n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • trigger multiple select 2 disabled/enabled\n
    • \n
    \n
    \n\n\n\n
    file upload (input[file]) -- without and with implicit labelling\n
      \n
    • \n \n
    • \n\n
    • \n
    • \n\n
    • \n \n
    • \n
    \n
    \n\n\n
    \n Check POST Data or Reset Data via Buttons (input[submit], input[reset], input[image])\n\n
      \n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n\n
    • \n \n
    • \n
    \n\n
    \n\n
    Advanced example: Search field\n
      \n
    • \n \n \" name=\"inputSearchSubmit\" />\n
    • \n
    \n
    \n
    \n\n \n \n \n \n \n \n \n \n\n", "cfe/modules/select/cfe.module.select.multiple.js": "/**\n * @module Selectable\n */\n\n/**\n * replaces select fields with attribute multiple set\n *\n * bug:\n * mouseWheel support needed\n * \n * @class SelectMultiple\n * @namespace cfe.module\n *\n * @extends cfe.module.Select\n */\ncfe.module.SelectMultiple = new Class({\n\t\n Extends: cfe.module.Select,\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"select[multiple]\",\n\n options: {\n buttonStyle: false\n },\n\n afterInitialize: function()\n {\n this.containerWrapper.addClass(cfe.prefix+\"SelectContainerWrapper\").setStyles({\n \"position\": \"relative\",\n \"z-index\": \"auto\"\n });\n this.container.addClass(cfe.prefix+\"SelectContainer\");\n\n this.o.addEvents({\n onDisable: function(){\n this.containerWrapper.getElements(\"input, button\").each(function(el){\n el.disable();\n });\n }.bind(this),\n onEnable: function(){\n this.containerWrapper.getElements(\"input, button\").each(function(el){\n el.enable();\n });\n }.bind(this)\n });\n \n this.parent();\n },\n\n setupWrapperEvents: function()\n {\n this.a = this.containerWrapper;\n this.parent();\n },\n\n buildOption: function(el, index)\n {\n var oOpt = new cfe.module.Checkbox({\n label: el.innerHTML,\n checked: $chk(el.selected),\n disabled: this.isDisabled()\n });\n oOpt.index = index;\n\n oOpt.addEvents({\n \"check\": function(index){\n this.origOptions[index].selected = true;\n this.o.fireEvent(\"change\")\n }.pass(index, this),\n \"uncheck\": function(index){\n this.origOptions[index].selected = false;\n this.o.fireEvent(\"change\")\n }.pass(index, this)\n });\n\n $(oOpt).addClass(cfe.prefix+\"Option \"+cfe.prefix+\"Option\"+index+(el.get('class')?\" \".el.get('class'):\"\")).disableTextSelection();\n oOpt.getLabel().removeEvents().inject( $(oOpt) );\n\n return $(oOpt);\n },\n\n selectOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n this.highlightOption(index);\n },\n\n clicked: function()\n {\n if(!this.isDisabled())\n {\n this.o.focus();\n this.fireEvent(\"onClick\");\n }\n },\n\n update: function()\n {\n this.fireEvent(\"onUpdate\");\n },\n\n toggle: function(){},\n keydown: function(){},\n hideContainer: function(){},\n showContainer: function(){}\n});"}, "files_after": {"cfe/modules/file/cfe.module.file.js": "/**\n * @module File\n */\n\n/**\n * replaces file upload fields\n *\n *

    is not resetted onReset

    \n * \n *
    Tested in:
    \n *
      \n *
    • Safari 4 - implicitly labelled triggers when deletin a file; reset doesnt trigger
    • \n *
    • Firefox 3.6.
    • \n *
    • Google Chrome 6 - implicitly labelled triggers twice, when using alias button & triggers when deletin a file.
    • \n *
    • Opera 10.62.
    • \n *
    • IE 7 - gaga.
    • \n *
    • IE 8 - implicitly labelled triggers when deletin a file.
    • \n *
    \n *\n * @class File\n * @namespace cfe.modules\n *\n * @extends cfe.module.Button\n */\n\ncfe.module.File = new Class({\n \n Extends: cfe.module.Button,\n \n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=file]\",\n\t\n options: {\n /**\n * enables the use of fileicons through a bit of markup and css\n * @config fileIcons\n * @type boolean\n * @default true\n */\n fileIcons: true,\n /**\n * show only the filename, not the whole path\n * @config trimFilePath\n * @type boolean\n * @default true\n */\n trimFilePath: true,\n\n innerLabel: \"Choose File\"\n },\n\n hideOriginalElement: false,\n\n toElement: function()\n {\n return this.wrapa\n },\n\n /**\n * retreive the filepath\n *\n * @method getFilePath\n * @return {HTMLElement}\n */\n getFilePath: function()\n {\n return this.v;\n },\n\n afterInitialize: function()\n {\n this.a = this.button;\n \n if(this.hideOriginalElement) this.o.hideInPlace();\n\n if(this.o.id) this.wrapa.addClass(cfe.prefix+this.type+this.o.id.capitalize());\n\n // various additions\n if(!this.o.implicitLabel && !Browser.safari && !Browser.chrome) this.wrapa.addEvent(\"click\", this.clicked.pass([e],this));\n\n if(this.isDisabled()) this.disable();\n\n if(!this.options.slidingDoors) this.wrapa.addClass(cfe.prefix+this.type)\n\n if(this.options.buttonStyle) this.a.addClass(cfe.prefix+\"Button\")\n\n this.a.removeClass(cfe.prefix+this.type)\n },\n\n build: function()\n {\n this.parent();\n this.innerlabel.set(\"text\", Array.pick(this.options.innerLabel, \"\"));\n\n // make original element follow mouse\n // setup wrapper\n this.wrapa = new Element(\"span\",{\n \"class\": cfe.prefix+this.type,\n styles:\n {\n overflow: \"hidden\",\n position: \"relative\"\n }\n }).cloneEvents(this.a)\n \n this.wrapa.inject(this.a, \"after\").adopt(this.a, this.o);\n\n // add positioning styles and events to \"hidden\" file input\n this.o.addEvents({\n \"mouseout\": this.update.bind(this),\n \"change\": this.update.bind(this),\n onDisable: this.disable.bind(this),\n onEnable: this.enable.bind(this)\n }).setStyles({\n opacity: \"0\",\n visibility: \"visible\",\n height: \"100%\",\n width: \"auto\",\n position: \"absolute\",\n top: 0,\n right: 0,\n margin: 0\n });\n\n this.wrapa.addEvent(\"mousemove\", this.follow.pass([e],this));\n\n this.button = this.a;\n this.a = this.wrapa;\n \n // add filepath\n this.v = new Element(\"span\").addClass(cfe.prefix+this.type+\"Path hidden\");\n\t\t\n this.path = new Element(\"span\").addClass(\"filePath\");\n\n if(this.options.fileIcons)\n {\n this.path.addClass(\"fileIcon\");\n }\n\n this.cross = $( new cfe.module.Button({delegateClick: false}).addEvent(\"click\", this.deleteCurrentFile.bind(this)) ).addClass(\"delete\");\n\n this.v.adopt(this.path, this.cross).inject(this.wrapa, \"after\");\n\n this.update();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"file\"\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n type: \"file\"\n });\n },\n\t\n follow: function(ev)\n {\n this.o.setStyle(\"left\",(ev.client.x-this.a.getLeft()-(this.o.getWidth()-30)));\n\t\t\n /* special treatment for internet explorer as the fileinput will not be cut off by overflow:hidden */\n if(Browser.ie){\n if(ev.client.x < this.a.getLeft() || ev.client.x > this.a.getLeft()+this.a.getWidth())\n this.o.setStyle(\"left\", -9999);\n }\n },\n\t\n update: function()\n {\n // only do stuff if original element is not disabled\n if( this.o.disabled == null )\n {\n if( this.o.value != \"\" )\n {\n this.o.disable().blur();\n\n this.oldValue = this.o.getProperty(\"value\");\n if(this.options.trimFilePath) this.oldValue = this.oldValue.trimFilePath();\n this.path.set(\"html\", this.oldValue);\n\n if(this.options.fileIcons)\n {\n var ind = this.oldValue.lastIndexOf(\".\");\n this.path.setProperty(\"class\",\"filePath fileIcon \" + this.oldValue.substring(++ind).toLowerCase());\n }\n this.v.removeClass(\"hidden\");\n }\n else\n {\n this.o.enable().focus();\n\n this.path.set(\"html\", \"\");\n this.v.addClass(\"hidden\");\n }\n\n this.parent();\n }\n },\n\t\n deleteCurrentFile: function()\n {\n // we dont clone the old file input here, since the attribute \"value\" would be cloned, too\n // and we cannot modify the value of an file input field without user interaction\n this.o = this.createOriginal().addClass(this.o.getProperty(\"class\")).setProperties({\n name: this.o.getProperty(\"name\"),\n id: this.o.getProperty(\"id\"),\n style: this.o.getProperty(\"style\"),\n title: this.o.getProperty(\"title\")\n }).cloneEvents(this.o).replaces(this.o);\n\t\t\n this.update();\n }\n});\n\n// add trimFilePath to Native String for convenience\nString.implement({\n trimFilePath: function()\n {\n var ind = false;\n if(!(ind = this.lastIndexOf(\"\\\\\")))\n if(!(ind = this.lastIndexOf(\"\\/\")))\n ind = 0;\n\n return this.substring(++ind);\n }\n});", "cfe/base/cfe.base.js": "/**\n * The core of custom form elements. Includes cfe.Generic and some slight addons to the native Element object. \n *\n * @module Core\n * @namespace cfe\n */\n\nvar cfe = {\n version: \"0.9.9\",\n prefix: \"cfe\",\n module: {},\n addon: {}\n};\n\n/**\n * extend Elements with some Helper functions\n * @class Helpers\n * @namespace Element\n */\nElement.Helpers = new Class({\n\n /**\n * cross-browser method for disabling the text selection by setting css attributes\n * \n * @method disableTextSelection\n */\n disableTextSelection: function(){\n if(Browser.ie || Browser.opera){\n this.setProperty(\"unselectable\",\"on\");\n }\n else if(Browser.firefox){\n this.setStyle(\"MozUserSelect\",\"none\");\n }\n else if(Browser.safari || Browser.chrome){\n this.setStyle(\"KhtmlUserSelect\",\"none\");\n }\n\n return this;\n },\n\n /**\n * disables a HTMLElement if its a form element by setting the disabled attribute to true\n *\n * @method disable\n * @return boolean true, if element could be disabled\n */\n disable: function()\n {\n if(typeOf(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", true);\n this.fireEvent(\"onDisable\");\n }\n\n return this;\n },\n\n /**\n * enables a HTMLElement if its a form element by setting the disabled attribute to false\n *\n * @method enable\n * @return {boolean} true, if element could be enabled\n */\n enable: function()\n {\n if(typeOf(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", false);\n this.fireEvent(\"onEnable\");\n }\n\n return this;\n },\n\n /**\n * enables or disabled a HTMLElement if its a form element depending on it's current state\n *\n * @method toggleDisabled\n * @return {boolean} true, if element could be toggled\n */\n toggleDisabled: function()\n {\n if(typeOf(this) === \"element\" && [\"button\", \"input\", \"option\", \"optgroup\", \"select\", \"textarea\"].contains( this.get(\"tag\") ) )\n {\n this.setProperty(\"disabled\", !this.getProperty(\"disabled\") );\n this.fireEvent(this.getProperty(\"disabled\")?\"onDisable\":\"onEnable\");\n }\n return this;\n },\n\n /**\n * returns the label-element which belongs to this element\n *\n * @method getLabel\n * @return HTMLElement or NULL\n */\n getLabel: function()\n {\n var label = null;\n\n // get label by id/for-combo\n if(this.id) label = $$(\"label[for=\"+this.id+\"]\")[0];\n \n // no label was found for id/for, let's see if it's implicitly labelled\n if(!label)\n {\n label = this.getParent('label');\n\n if(label) this.implicitLabel = true;\n }\n\n return label;\n },\n\n /**\n * generates the markup used by sliding doors css technique to use with this element\n *\n * @method setSlidingDoors\n *\n * @param count\n * @param type\n * @param prefix\n * \n * @return HTMLElement or NULL the wrapped HTMLElement\n */\n setSlidingDoors: function(count, type, prefix, suffixes)\n {\n var slide = null;\n var wrapped = this;\n prefix = Array.pick(prefix, \"sd\");\n\n suffixes = Array.pick(suffixes, []);\n\n for(var i = count; i > 0; --i)\n {\n wrapped.addClass( prefix+\"Slide\"+( (i == 1 && count == i) ? \"\" : (suffixes[i] || i) ));\n slide = new Element(type);\n try{\n wrapped = slide.wraps(wrapped);\n }catch(e){\n wrapped = slide.grab(wrapped);\n }\n }\n\n wrapped = null;\n\n return slide;\n },\n\n /**\n * hide an element but keep it's vertical position and leave it tab- & screenreader-able :)\n *\n * @method hideInPlace\n *\n * @return HTMLElement\n */\n hideInPlace: function()\n {\n return this.setStyles({\n position: \"absolute\",\n left: -99999,\n width: 1,\n height: 1\n });\n }\n});\n\nElement.implement(new Element.Helpers);", "cfe/modules/check/cfe.module.radio.js": "/**\n * @module Checkable\n */\n\n/**\n *

    replaces radiobuttons

    \n *\n *
    Tested in:
    \n *
      \n *
    • Safari 4.
    • \n *
    • Firefox 3.6.
    • \n *
    • Google Chrome 6.
    • \n *
    • Opera 10.62.
    • \n *
    • IE 7.
    • \n *\n *
    • IE 8\n *
        \n *
      • labels dont work for normal labelled elements
      • \n *
      \n *
    • \n *\n *
    \n *\n * @class Radiobutton\n * @namespace cfe.module\n *\n * @extends cfe.modules.Checkbox\n */\ncfe.module.Radiobutton = new Class({\n\n Extends: cfe.module.Checkbox,\n\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=radio]\",\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"radio\"\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n \"type\": \"radio\",\n \"checked\": this.options.checked\n });\n },\n\n /**\n * @method initializeAdv\n * @protected\n */\n afterInitialize: function()\n {\n this.parent();\n \n if( !(Browser.ie || Browser.firefox) ) this.o.addEvent(\"click\", this.update.bind(this));\n\n // on check, disable all other radiobuttons in this group\n this.addEvent(\"check\", function(){\n $$(\"input[name='\"+this.o.get(\"name\")+\"']\").each(function(el)\n {\n if(el != this.o && el.retrieve(\"cfe\")) el.retrieve(\"cfe\").uncheck();\n }.bind(this));\n })\n }\n});", "cfe/replace/cfe.replace.js": "/**\n * replacement class for automated replacment of scoped form elements\n *\n * @module replace\n * @namespace cfe\n *\n */\n\ncfe.Replace = new Class(\n{\n Implements: [new Options, new Events],\n\n options:{\n scope: false,\n\t\t\n onInit: function(){},\n onInitSingle: function(){},\n onBeforeInitSingle: function(){},\n onSetModuleOption: function(){},\n onRegisterModule: function(){},\n onUnregisterModule: function(){},\n onComplete: function(){}\n },\n\t\t\n modules: {},\n moduleOptions: {},\n moduleOptionsAll: {},\n\t\n initialize: function()\n {\n this.registerAllModules.bind(this)();\n },\n\t\n /**\n * @method registerAllModules\n\t * registeres all loaded modules onInitialize\n\t */\n registerAllModules: function(){\n\t\t\n //console.log(\"Register all modules\");\n\t\t\n Object.each(cfe.module, function(modObj, modType){\n //console.log(\"Registering type \"+modType);\n if(modType != \"Generic\")\n this.registerModule(modType);\n\t\t\t\t\n },this);\n },\n\t\n /* call to register module */\n registerModule: function(mod){\n\t\t\n //console.log(\"Call to registerModule with arg:\"+mod);\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onRegisterModule\", [mod,modObj]);\n this.modules[mod] = modObj;\n this.moduleOptions[mod] = {};\n\n return true;\n },\n\t\n registerModules: function(mods)\n {\n Object.each(mods,function(mod){\n this.registerModule(mod);\n },this);\n },\n\t\n unregisterModule: function(mod)\n {\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onUnregisterModule\", [mod,modObj]);\n\n delete this.modules[mod];\n },\n\t\n unregisterModules: function(mods)\n {\n Object.each(mods,function(mod){\n this.unregisterModule(mod);\n },this);\n },\n /**\n\t * sets a single option for a specified module\n\t * if no module was given, it sets the options for all modules\n\t *\n * @method setModuleOption\n *\n\t * @param {String} \tmod \tName of the module\n\t * @param {String} \topt \tName of the option\n\t * @param {Mixed} \tval\t\tThe options value\n\t */\n setModuleOption: function(mod,opt,val){\n\t\t\n modObj = cfe.module[mod];\n\t\t\n this.fireEvent(\"onSetModuleOption\", [mod,modObj,opt,val]);\n\t\t\n if(!modObj){\n this.moduleOptionsAll[opt] = val;\n }\n else{\n this.moduleOptions[mod][opt] = val;\n }\n },\n\n setModuleOptions: function(mod,opt){\n\t\t\n Object.each(opt, function(optionValue, optionName){\n this.setModuleOption(mod,optionName,optionValue);\n },this);\n\t\t\n },\n\n engage: function(options){\n\n this.setOptions(this.options, options);\n\n if(typeOf(this.options.scope) != \"element\"){\n this.options.scope = $(document.body);\n }\n\n this.fireEvent(\"onInit\");\n\t\t\n Object.each(this.modules,function(module,moduleName,i){\n\t\t\t\n var selector = module.prototype.selector;\n\t\t\t\n this.options.scope.getElements(selector).each(function(el,i){\n\n if(el.retrieve(\"cfe\") != null){\n\n var basicOptions = {\n replaces: el\n };\n\n this.fireEvent(\"onBeforeInitSingle\", [el,i,basicOptions]);\n\n var single = new module(Object.merge({},basicOptions,Object.merge({},this.moduleOptions[moduleName],this.moduleOptionsAll)));\n\t\t\t\t\n this.fireEvent(\"onInitSingle\", single);\n }else{\n this.fireEvent(\"onSkippedInitSingle\", [el,i,basicOptions]); \n }\n\t\t\t\t\n },this);\n },this);\n\t\t\n this.fireEvent(\"onComplete\");\n }\n});", "cfe/modules/check/cfe.module.checkbox.js": "/**\n * @module Checkable\n */\n\n/**\n *

    replaces checkboxes

    \n * \n *
    Tested in:
    \n *
      \n *
    • Safari 4.
    • \n *
    • Firefox 3.6.
    • \n *
    • Google Chrome 6.
    • \n *
    • Opera 10.62.
    • \n *
    • IE 7.
    • \n *
    • IE 8.
    • \n *
    \n *\n * @class Checkbox\n * @namespace cfe.module\n * \n * @extends cfe.module.Button\n */\ncfe.module.Checkbox = new Class({\n \n Extends: cfe.module.Button,\n \n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"input[type=checkbox]\",\n\n options:{\n /**\n * @inherit\n */\n slidingDoors: false\n /**\n * Fired when the original element gets checked\n * @event onCheck\n */\n //onCheck: Class.empty,\n /**\n * Fired when the original element's checked state is set to false\n * @event onUnCheck\n */\n //onUncheck: Class.empty\n },\n\n afterInitialize: function()\n {\n this.parent();\n\n // important for resetting dynamically created cfe\n this.o.defaultChecked = this.o.checked;\n\n if( Browser.ie || Browser.opera )\n {\n //console.log(\"fix for element update (IE and Opera)\")\n this.o.addEvent(\"click\", this.update.bind(this) );\n }\n\n\n if(Browser.ie && this.o.implicitLabel)\n {\n //console.log(\"fix for implicit labels (IE) element[\"+this.o.id+\"]\")\n this.l.removeEvents(\"click\")\n this.a.removeEvents(\"click\").addEvent(\"click\", function(e){\n e.stop();\n this.clicked.bind(this)();\n }.bind(this))\n }\n\n this.update();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} an input field of type \"checkbox\"\n * @protected\n */\n createOriginal: function()\n {\n return new Element(\"input\",{\n type: \"checkbox\",\n checked: this.options.checked\n });\n },\n\n clicked: function(e)\n {\n if(Browser.ie && e) e.stop();\n\n this.parent()\n },\n\n /**\n * public method to check a checkbox programatically\n *\n * @method check\n * @public\n */\n check: function()\n {\n this.a.addClass(\"A\");\n this.fireEvent(\"onCheck\");\n },\n\n /**\n * public method to uncheck a checkbox programatically\n *\n * @method uncheck\n * @public\n */\n uncheck: function()\n {\n this.a.removeClass(\"A\");\n this.fireEvent(\"onUncheck\");\n },\n\n update: function()\n {\n this.o.checked ? this.check() : this.uncheck();\n this.parent();\n }\n});", "cfe/addons/cfe.addon.toolTips.js": "/**\n * @module Addon\n */\n\n/**\n * pretty simple integration of auto-generated tooltips (from title-attribute)\n * depends on mootools Tips\n *\n * @class Tips\n * @namespace cfe.addon\n *\n */\ncfe.addon.Tips = new Class({\n\t\n options: Object.merge({},this.parent, {\n enableTips: true,\n ttStyle: \"label\",\n ttClass: cfe.prefix+\"Tip\"\n }),\n\t\n initToolTips: function(){\n\t\t\n if(!window.Tips || !this.options.enableTips){\n if(this.options.debug){\n this.throwMsg.bind(this)(\"CustomFormElements: initialization of toolTips failed.\\nReason: Mootools Plugin 'Tips' not available.\");\n }\n \n return false;\n }\n\t\n switch(this.options.ttStyle){\n default:case 'label': this.toolTipsLabel.bind(this)();break;\n }\n\n return true;\n },\n\t\n toolTipsLabel: function(){\n\t\t\n var labels = this.options.scope.getElements('label');\n \t\t\n labels.each(function(lbl,i){\n\n forEl = lbl.getProperty(\"for\");\n\t\t\t\n if(!forEl){\n var cl = lbl.getProperty(\"class\");\n\t\t\t\t\n if( cl != null ){\n var forEl = cl.match(/for_[a-zA-Z0-9\\-]+/);\n\n if(forEl){\n forEl = forEl.toString();\n el = $( forEl.replace(/for_/,\"\") );\n } \n }\n\t\t\t\t\n if(!el){\n el = lbl.getElement(\"input\");\n }\n }else{\n el = $(forEl);\n }\n\n if(el){\n if((qmTitle = el.getProperty(\"title\")) != null){\n\t\t\t\t\t\n el.setProperty(\"title\",\"\").setProperty(\"hint\", qmTitle)\n\t\t\t\t\t\n var qm = new Element(\"span\",{\n \"class\": this.options.ttClass,\n \"title\": qmTitle\n });\n \n // check if implicit label span is present\n var impLabel = lbl.getFirst(\"span[class=label]\");\n \n qm.inject((impLabel != null)?impLabel:lbl,'inside');\n }\n }\n },this);\n\t\t\n new Tips($$('.'+this.options.ttClass+'[title]'));\n }\n});\n\ncfe.Replace.implement(new cfe.addon.Tips);\ncfe.Replace.prototype.addEvent(\"onComplete\", function(){\n this.initToolTips();\n});", "cfe/addons/cfe.addon.dependencies.js": "/**\n * @module Addon\n */\n\n/**\n * adds dependencies to checkboxes\n *\n * @class Dependencies\n * @namespace cfe.addon\n *\n */\ncfe.addon.Dependencies = new Class({\n\t\n /**\n\t * adds dependencies for an element \n\t * @param {Object} el\n\t * @param {Array} dep\n\t */\n addDependencies: function(el, deps){\n Array.each(deps,function(dep){\n this.addDependency(el,dep);\n },this);\n },\n\t\n /**\n\t * adds dependency for an element \n\t * @param {Object} el\n\t * @param {Object} dep\n\t */\n addDependency: function(el, dep){\n\t\t\n // create an array if needed\n if(typeOf( el.retrieve('deps') ) !== \"array\"){\n el.store('deps', []);\n }\n\t\t\n // deps may be objects or strings > if a string was given, try to interpret it as id and fetch element by $()\n if(typeOf(dep) === \"string\" || typeOf(dep) === \"element\"){\n el.retrieve('deps').push( $(dep) );\n return true;\n }\n\t\t\n return false;\n },\n\t\n getDependencies: function(el)\n {\n return el.retrieve('deps');\n },\n\t\n /**\n\t * this is called when a new item of a cfemodule gets initialized\n\t * it checks, whether there are dependencies for this element and adds them to its options\n\t * \n\t * @param {Object} el\n\t */\n attachDependencies: function(el,i,baseOptions)\n {\n var deps = this.getDependencies(el);\n\t\t\n if(typeOf(deps) === \"array\"){\n baseOptions.deps = deps;\n return true;\n }\n\t\n return false;\n }\n\t\t\n});\ncfe.Replace.implement(new cfe.addon.Dependencies);\ncfe.Replace.prototype.addEvent(\"onBeforeInitSingle\", cfe.Replace.prototype.attachDependencies);\n\ncfe.addon.Dependencies.Helper = new Class({\n resolveDependencies: function()\n {\n var deps = this.o.retrieve('deps');\n\t\t\n if(deps){\n Array.each(deps, function(dep,i){\n dep.checked = true;\n dep.fireEvent(\"change\");\n },this);\n }\n }\n});\n\n// support for checkboxes\ncfe.module.Checkbox.implement(new cfe.addon.Dependencies.Helper);\ncfe.module.Checkbox.prototype.addEvent(\"onCheck\", function(){\n this.resolveDependencies();\n});", "cfe/modules/button/cfe.module.button.js": "/**\n * @module Button\n */\n\n/**\n * gets extended by modules to start off with standard, button-like behaviours.\n *\n * when focused and pressed, form gets submitted\n *\n * @class Button\n * @namespace cfe.module\n *\n */\ncfe.module.Button = new Class(\n{\n Implements: [new Options, new Events],\n\n selector: \"button\",\n\n instance: 0,\n\n /**\n * basic options for all cfes and always available\n * @property options\n */\n options: {\n /**\n * if > 0, it will create markup for css sliding doors tech
    \n * the number defines the amount of wrappers to create around this element
    \n * 2: standard sliding doors (x- or y-Axis)
    \n * 4: sliding doors in all directions (x/y-Axis)\n *\n * @config slidingDoors\n * @type int\n * @default 4\n */\n slidingDoors: 2,\n\n /**\n * if this element shall replace an existing html form element, pass it here\n * @config replaces\n * @type HTMLElement\n */\n replaces: null,\n\n /**\n * determines if a click on the decorator should be delegated to the original element\n * @config delegateClick\n * @type Boolean\n */\n delegateClick: true,\n\n /**\n * may pass any element as a label (toggling, hovering,..) for this cfe\n * @config label\n * @type HTMLElement\n */\n label: null,\n\n /**\n * if this cfe is created programatically, it's possible to set the name attribute of the generated input element\n * @config name\n * @type string\n */\n name: \"\",\n\n /**\n * setting this to true will create a disabled element\n * @config disabled\n * @type boolean\n */\n disabled: false,\n\n buttonStyle: true\n\n /**\n * Fired when the mouse is moved over the \"decorator\" element\n * @event onMouseOver\n */\n //onMouseOver: Class.empty,\n\n /**\n * Fired when the mouse is moved away from the \"decorator\" element\n * @event onMouseOut\n */\n //onMouseOut: Class.empty,\n\n /**\n * Fired when the \"original\" element gets focus (e.g. by tabbing)\n * @event onFocus\n */\n //onFocus: Class.empty,\n\n /**\n * Fired when the \"original\" element loses focus\n * @event onBlur\n */\n //onBlur: Class.empty,\n\n /**\n * Fired when \"decorator\" is clicked by mouse\n * @event onClick\n */\n //onClick: Class.empty,\n\n /**\n * Fired when pressing down with the mouse button on the \"decorator\"\n * Fired when pressing the space key while \"original\" has focus\n * @event onPress\n */\n //onPress: Class.empty,\n\n /**\n * Fired when \"decorator\" was pressed and the mouse button is released\n * Fired when \"original\" was pressed by space key and this key is released\n * @event onRelease\n */\n //onRelease: Class.empty,\n\n /**\n * Fired when \"original\"'s value changes\n * @event onUpdate\n */\n //onUpdate: Class.empty,\n\n /**\n * Fired when \"original\" gets disabled by HTMLElement.enable()\n * @event onEnable\n */\n //onEnable: Class.empty,\n\n /**\n * Fired when \"original\" gets disabled by HTMLElement.disable()\n * @event onDisable\n */\n //onDisable: Class.empty,\n\n /**\n * Fired when decorator is completely loaded and is ready to use\n * @event onLoad\n */\n //onLoad: Class.empty\n\n\n },\n\n hideOriginalElement: true,\n\n /**\n * constructor
    \n * building algorithm for cfe (template method)
    \n *
      \n *
    1. setOptions: set Options
    2. \n *
    3. buildWrapper: setup the \"decorator\"
    4. \n *
    5. setupOriginal: procede the \"original\" element (add Events...)
    6. \n *
    7. addLabel: add and procede the label
    8. \n *
    9. initializeAdv: last chance for subclasses to do initialization
    10. \n *
    11. build: various specific dom handling and \"decorator\" building
    12. \n *\n * @method initialize\n * @constructor\n *\n * @param {Object} options\n **/\n initialize: function(opt)\n {\n // sets instance id\n this.instance = this.constructor.prototype.instance++;\n\n this.setOptions(opt);\n\n this.type = Array.pick(this.options.type, cfe.module.keyOf(this.constructor));\n\n this.buildWrapper();\n\n // prepares original html element for use with cfe and injects decorator into dom\n this.setupOriginal();\n\n // add a label, if present\n this.addLabel( Array.pick(this.o.getLabel(), this.setupLabel(this.options.label) ) );\n\n this.build();\n\n // add events to wrapping element\n this.setupWrapperEvents();\n\n // specific initialization\n this.afterInitialize();\n\n this.fireEvent(\"load\")\n },\n\n /**\n * retreive the \"decorator\"\n * mootools supports the use of $(myCfe) if toElement is defined\n *\n * @method toElement\n * @return {HTMLElement}\n */\n toElement: function()\n {\n return this.a;\n },\n\n /**\n * retreive the label\n *\n * @method getLabel\n * @return {HTMLElement}\n */\n getLabel: function()\n {\n return this.l;\n },\n\n /**\n * template method STEP 1\n */\n buildWrapper: function(){\n this.a = new Element(\"span\");\n },\n\n /**\n * handles the creation of the underlying original form element
      \n * stores a reference to the cfe object in the original form element\n * template method STEP 2\n *\n * @method setupOriginal\n * @protected\n */\n setupOriginal: function()\n {\n // get original element\n if( this.options.replaces != null )\n {\n this.o = this.options.replaces;\n this.a.inject(this.o, 'before');\n }\n else // standalone\n {\n this.o = this.createOriginal();\n\n if(this.options.id) this.o.setProperty(\"id\", this.options.id);\n\n if(this.options.disabled) this.o.disable();\n\n if(this.options.name)\n {\n this.o.setProperty(\"name\", this.options.name);\n\n if( this.o.id == null ) this.o.setProperty(\"id\", this.options.name+this.instance);\n }\n\n if(this.options.value) this.o.setProperty(\"value\", this.options.value);\n\n this.a.adopt(this.o);\n }\n\n this.o.addEvents({\n focus: this.setFocus.bind(this),\n blur: this.removeFocus.bind(this),\n change: this.update.bind(this),\n keydown: function(e){\n if(e.key == \"space\") this.press();\n }.bind(this),\n keyup: function(e){\n if(e.key == \"space\") this.release();\n }.bind(this),\n onDisable: function(){\n this.a.fireEvent(\"disable\");\n }.bind(this),\n onEnable: function(){\n this.a.fireEvent(\"enable\");\n }.bind(this)\n });\n\n // store a reference to this cfe \"in\" the original form element\n this.o.store(\"cfe\", this);\n },\n\n /*\n * adds a label element to this cfe\n * template method STEP 3\n *\n * @method addLabel\n * @protected\n *\n * @param {HTMLElement} the label element to set as label for this cfe\n */\n addLabel: function(label)\n {\n if( label == null ) return;\n\n this.l = label;\n\n // remove for property\n if(!this.dontRemoveForFromLabel) this.l.removeProperty(\"for\");\n\n // add adequate className, add stdEvents\n this.l.addClass(cfe.prefix+this.type+\"L\");\n\n if(this.o.id || this.o.name) this.l.addClass(\"for_\"+ (this.o.id || (this.o.name+this.o.value).replace(\"]\",\"-\").replace(\"[\",\"\") ));\n\n // add stdevents\n this.l.addEvents({\n mouseover: this.hover.bind(this),\n mouseout: this.unhover.bind(this),\n mousedown: this.press.bind(this),\n mouseup: this.release.bind(this),\n click: this.clicked.bind(this,[e])\n });\n\n this.addEvents({\n press: function()\n {\n this.l.addClass(\"P\");\n },\n release: function()\n {\n this.l.removeClass(\"P\");\n },\n mouseOver: function()\n {\n this.l.addClass(\"H\");\n },\n mouseOut: function()\n {\n this.l.removeClass(\"H\");\n this.l.removeClass(\"P\");\n },\n focus: function()\n {\n this.l.addClass(\"F\");\n },\n blur: function()\n {\n this.l.removeClass(\"F\");\n //this.l.removeClass(\"P\");\n },\n enable: function()\n {\n this.l.removeClass(\"D\");\n },\n disable: function()\n {\n this.l.addClass(\"D\");\n }\n });\n },\n\n /**\n * part of the main template method for building the \"decorator\"
      \n * must be extended by subclasses\n *\n * template method STEP 4\n *\n * @method build\n * @protected\n */\n build: function(){\n\n this.innerlabel = this.setupInnerLabel();\n this.a.adopt(this.innerlabel);\n\n if( this.options.slidingDoors != null )\n {\n this.a = this.a.setSlidingDoors(this.options.slidingDoors-1, \"span\", cfe.prefix).addClass(cfe.prefix+this.type);\n }\n },\n\n\n /**\n * adds events and mousepointer style to the \"decorator\"\n * usually gets called by buildWrapper\n *\n * template method STEP 5\n *\n * @method setupWrapperEvents\n * @protected\n */\n setupWrapperEvents: function()\n {\n if(!this.o.implicitLabel)\n {\n this.a.addEvents({\n mouseover: this.hover.bind(this),\n mouseout: this.unhover.bind(this),\n mousedown: this.press.bind(this),\n mouseup: this.release.bind(this)\n });\n }\n\n this.a.addEvents({\n disable: this.disable.bind(this),\n enable: this.enable.bind(this)\n })\n \n },\n\n /**\n * part of the main template method for building the \"decorator\"
      \n * gets called immediately before the build-method
      \n * may be extended by subclasses\n *\n * template method STEP 6\n *\n * @method initializeAdv\n * @protected\n */\n afterInitialize: function()\n {\n if(this.hideOriginalElement) this.o.hideInPlace();\n\n if(this.o.id) this.a.addClass(cfe.prefix+this.type+this.o.id.capitalize());\n\n // various additions\n if(!this.o.implicitLabel) this.a.addEvent(\"click\", this.clicked.pass([e],this));\n\n if(this.isDisabled()) this.a.fireEvent(\"disable\");\n\n if(!this.options.slidingDoors) this.a.addClass(cfe.prefix+this.type)\n\n if(this.options.buttonStyle) this.a.addClass(cfe.prefix+\"Button\")\n },\n\n setupInnerLabel: function(){\n return new Element(\"span\").addClass(\"label\").disableTextSelection();\n },\n\n\n /**\n * getter for retrieving the disabled state of the \"original\" element\n *\n * @method isDisabled\n * @return boolean\n */\n isDisabled: function()\n {\n return this.o.getProperty(\"disabled\")\n },\n\n /**\n * programatically creates an \"original\" element
      \n * each subclass has to implement this\n *\n * @method createOriginal\n * @return {HTMLElement}\n */\n createOriginal: function()\n {\n return new Element(\"button\")\n },\n\n /*\n * creates a label element and fills it with the contents (may be html) given by option \"label\"\n *\n * @method setupLabel\n * @protected\n *\n * @return {HTMLElement or NULL} if option \"label\" is not set\n */\n setupLabel: function()\n {\n if( this.options.label != null ) return new Element(\"label\").set(\"html\", this.options.label).setProperty(\"for\", this.o.id);\n\n return null;\n },\n\n /**\n * wrapper method for event onPress
      \n * may be extended by subclasses\n *\n * @method press\n * @protected\n */\n press: function()\n {\n if(this.isDisabled()) return\n\n this.a.addClass(\"P\");\n this.fireEvent(\"onPress\");\n\n //console.log(this.type + \"pressed\");\n },\n\n /**\n * wrapper method for event onRelease
      \n * may be extended by subclasses\n *\n * @method release\n * @protected\n */\n release: function()\n {\n if(this.isDisabled()) return\n\n this.a.removeClass(\"P\");\n this.fireEvent(\"onRelease\");\n \n //console.log(this.type + \"released\");\n\n },\n\n /**\n * wrapper method for event onMouseOver
      \n * may be extended by subclasses\n *\n * @method onMouseOver\n * @protected\n */\n hover: function()\n {\n if(this.isDisabled()) return\n\n this.a.addClass(\"H\");\n this.fireEvent(\"onMouseOver\");\n\n //console.log(this.type + \"hovered\");\n },\n\n /**\n * wrapper method for event onMouseOut
      \n * may be extended by subclasses\n *\n * @method unhover\n * @protected\n */\n unhover: function()\n {\n if(this.isDisabled()) return\n\n this.a.removeClass(\"H\");\n this.fireEvent(\"onMouseOut\");\n this.release();\n\n //console.log(this.type + \"unhovered\");\n },\n\n /**\n * wrapper method for event onFocus
      \n * may be extended by subclasses\n *\n * @method setFocus\n * @protected\n */\n setFocus: function()\n {\n this.a.addClass(\"F\");\n this.fireEvent(\"onFocus\");\n\n //console.log(this.type + \"focused\");\n },\n\n /**\n * wrapper method for event onBlur
      \n * may be extended by subclasses\n *\n * @method removeFocus\n * @protected\n */\n removeFocus: function()\n {\n //console.log(\"o blurred\");\n this.a.removeClass(\"F\");\n // if cfe gets blurred, also clear press state\n //this.a.removeClass(\"P\");\n this.fireEvent(\"onBlur\");\n\n //console.log(this.type + \"blurred\");\n\n },\n\n /**\n * wrapper method for event onClick
      \n * delegates the click to the \"original\" element
      \n * may be extended by subclasses\n *\n * @method clicked\n * @protected\n */\n clicked: function(e)\n {\n //causes problems in other browsers than ie - gonna took into this later; its the best approach to stop the event from bubbling right here though imho\n //e.stop();\n\n if(this.isDisabled()) return\n\n if( $chk(this.o.click) && this.options.delegateClick != null ) this.o.click();\n this.o.focus();\n\n this.fireEvent(\"onClick\");\n\n //console.log(this.type + \" clicked\");\n },\n\n /**\n * wrapper method for event onUpdate
      \n * may be extended by subclasses\n *\n * @method update\n * @protected\n */\n update: function()\n {\n this.fireEvent(\"onUpdate\");\n\n //console.log(\"o was updated\");\n },\n\n /**\n * wrapper method for event onEnable
      \n * may be extended by subclasses\n *\n * @method enable\n * @protected\n */\n enable: function()\n {\n this.a.removeClass(\"D\");\n this.fireEvent(\"onEnable\");\n\n //console.log(this.type+\"-\"+this.instance+\" now enabled\");\n },\n\n /**\n * wrapper method for event onDisable
      \n * may be extended by subclasses\n *\n * @method disable\n * @protected\n */\n disable: function()\n {\n this.a.addClass(\"D\");\n this.fireEvent(\"onDisable\");\n\n //console.log(this.type+\"-\"+this.instance+\" now disabled\");\n }\n});", "cfe/modules/select/cfe.module.select.js": "/**\n * @module Scrollable\n */\n\n/**\n * SCROLLING functionality for select boxes;\n * TODO: refactor to standalone module\n * \n * creates handles and sets up a slider object\n *\n * @class Scrollable\n * @namespace cfe.helper\n *\n * \n */\ncfe.helper = cfe.helper || {}\n\ncfe.helper.Scrollable = {\n\n options: {\n size: 4,\n scrolling: true\n },\n \n setupScrolling: function()\n {\n // slider config\n this.scrollerWrapper = new Element(\"span\",{\n \"class\": cfe.prefix+\"ScrollerWrapper\",\n \"styles\":{\n height: this.container.getHeight()\n }\n }).inject(this.container, \"after\");\n\n var scrollTimer, scrollTimeout;\n var scrollStepHeight = this.allOptions[0].getHeight();\n\n function scroll(by){\n clearInterval(scrollTimer);\n clearTimeout(scrollTimeout);\n\n slider.set(slider.step+by);\n\n scrollTimeout = (function(){\n scrollTimer = (function(){\n slider.set(slider.step+by);\n }.bind(this)).periodical(50)\n }.bind(this)).delay(200)\n }\n\n function clearScroll(){\n clearInterval(scrollTimer);\n clearTimeout(scrollTimeout);\n }\n\n this.scrollerTop = $(new cfe.module.Button({\n delegateClick: false\n }).addEvent(\"release\", clearScroll).addEvent(\"press\", scroll.pass(-1))).addClass(\"scrollTop\");\n\n this.scrollerBottom = $(new cfe.module.Button({\n delegateClick: false\n }).addEvent(\"release\", clearScroll).addEvent(\"press\", scroll.pass(1))).addClass(\"scrollBottom\")\n\n this.scrollerKnob = new Element(\"span\").addClass(\"scrollKnob\");\n this.scrollerBack = new Element(\"span\").addClass(\"scrollRail\");\n\n this.scrollerBack.adopt(this.scrollerKnob);\n this.scrollerWrapper.adopt(this.scrollerBack, this.scrollerTop, this.scrollerBottom);\n\n var slider = new Slider(this.scrollerBack, this.scrollerKnob, {\n steps: this.allOptions.length-this.options.size,\n mode: \"vertical\" ,\n onChange: function(step){\n this.container.scrollTo(false,step*scrollStepHeight);\n }.bind(this)\n }).set(this.selectedIndex);\n\n this.scrollerKnob.setStyle(\"position\", \"absolute\");\n\n // scrolling\n function wheelListener(ev)\n {\n ev.stop();\n slider.set(slider.step-ev.wheel);\n }\n\n this.boundWheelListener = wheelListener.pass([e],this)\n\n this.addEvent(\"containerShow\", function(){\n $(document.body).addEvent(\"mousewheel\", this.boundWheelListener)\n\n slider.set(this.o.selectedIndex);\n this.container.scrollTo(false,this.o.selectedIndex*scrollStepHeight);\n })\n\n this.addEvent(\"containerHide\", function(){\n $(document.body).removeEvent(\"mousewheel\", this.boundWheelListener);\n })\n\n this.o.addEvent(\"change\", function(){\n slider.set(this.o.selectedIndex)\n }.bind(this))\n }\n}\n\n/**\n * @module Selectable\n */\n\n/**\n * replaces select fields\n *\n *

      disabled should also disable scrolling

      \n * \n *
      Tested in:
      \n *
        \n *
      • Safari 4.
      • \n *
      • Firefox 3.6.
      • \n *
      • Google Chrome 6.
      • \n *
      • Opera 10.62 - key autocompletion closes box.
      • \n *
      • IE 7.
      • \n *
      • IE 8.
      • \n *
      \n *\n * @class Select\n * @namespace cfe.module\n *\n * @extends cfe.module.Button\n *\n */\ncfe.module.Select = new Class({\n\t\n Extends: cfe.module.Button,\n Implements: cfe.helper.Scrollable,\n \n Binds: \"clickedOutsideListener\",\n\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"select:not(select[multiple])\",\n\t\n selectedIndex: 0,\n\n setupOriginal: function()\n {\n this.parent();\n \n this.o.addEvents({\n \"keyup\": this.keyup.bind(this),\n \"keydown\": this.keydown.bind(this)\n });\n },\n\n afterInitialize: function()\n {\n this.parent();\n\n // set width to widest option if no width is given to select via css\n if(this.cssWidth == \"auto\") this.a.setStyle(\"width\", this.container.getWidth())\n\n // inject labelArrow as IE 7 doesn't support :after css selector\n if(Browser.ie) new Element(\"span\").addClass(\"labelArrow\").inject(this.innerlabel, \"after\")\n\n // select default option\n if(this.selectedIndex != -1) this.selectOption(this.selectedIndex, true);\n\n if(this.options.scrolling)\n {\n this.container.setStyle(\"height\", this.allOptions[0].getHeight()*this.options.size);\n this.setupScrolling();\n }\n\n this.hideContainer();\n },\n\n /**\n * Method to programmatically create an \"original\" HTMLElement\n *\n * @method createOriginal\n * @return {HTMLElement} a select input\n */\n createOriginal: function()\n {\n var ori = new Element(\"select\");\n\n if( this.options.options != null )\n {\n for(var key in this.options.options)\n {\n ori.adopt( new Element(\"option\", {\n value: key,\n selected: this.options.options[key].selected?\"selected\":\"\"\n }).set(\"html\", this.options.options[key].label ) );\n }\n }\n return ori;\n },\n\n build: function()\n {\n this.origOptions = this.o.getChildren();\n\n this.selectedIndex = this.o.selectedIndex || this.selectedIndex;\n\n // integrity check\n if(this.options.size > this.origOptions.length || this.options.scrolling != true) this.options.size = this.origOptions.length;\n \n this.parent();\n\n this.a.setStyles({\"position\": \"relative\", \"z-index\": 100000 - this.instance});\n\n // build container which shows on click\n this.buildContainer();\n\n this.cssWidth = this.a.getStyle(\"width\");\n },\n\n buildContainer: function()\n {\n this.container = new Element(\"span\",{\n \"class\": cfe.prefix+this.type+\"Container\",\n \"styles\":{\n \"overflow\":\"hidden\"\n }\n });\n \n this.containerWrapper = this.container.setSlidingDoors(4, \"span\", cfe.prefix).addClass(cfe.prefix+this.type+\"ContainerWrapper\").setStyles({\n position: \"absolute\",\n \"z-index\": this.instance + 1\n }).inject(this.a);\n\n // insert option elements\n this.allOptions = [];\n this.origOptions.each(function(el,i)\n {\n this.allOptions.push(this.buildOption(el, i))\n }.bind(this));\n\n this.container.adopt(this.allOptions);\n\n },\n\n buildOption: function(el, i)\n {\n return new Element(\"span\",{\n \"class\": cfe.prefix+\"Option \"+cfe.prefix+\"Option\"+i+(el.get('class')?\" \"+el.get('class'):\"\"),\n \"events\":{\n \"mouseover\": this.highlightOption.pass([i,true],this)/*,\n \"mouseout\": this.highlightOption.pass([i,true],this)*/\n }\n }).set('html', el.innerHTML.replace(/\\s/g, \" \")).disableTextSelection().store(\"index\", i);\n },\n\n selectOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n this.highlightOption(index);\n\n this.selectedIndex = index;\n\n this.innerlabel.set('html', (this.allOptions[index]).innerHTML);\n\n this.fireEvent(\"onSelectOption\", index);\n },\n\n highlightOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n if(this.highlighted) this.highlighted.removeClass(\"H\");\n\n this.highlighted = this.allOptions[index].addClass(\"H\");\n\n this.highlightedIndex = index;\n\n this.fireEvent(\"onHighlightOption\", index);\n },\n\n updateOption: function(by)\n {\n // fix for IE 7\n if(this.containerWrapper.retrieve(\"hidden\") != true && !Browser.ie) this.o.selectedIndex = (this.highlightedIndex+by).limit(0,this.origOptions.length-1);\n this.o.fireEvent(\"change\");\n },\n\n hideContainer: function()\n {\n $(document.body).removeEvent(\"click\", this.clickedOutsideListener);\n \n this.containerWrapper.setStyle(\"display\",\"none\").removeClass(\"F\").store(\"hidden\", true);\n\n this.fireEvent(\"onContainerHide\", this.selectedIndex);\n },\n\n showContainer: function()\n {\n $(document.body).addEvent(\"click\", this.clickedOutsideListener);\n\n this.containerWrapper.setStyle(\"display\", \"block\").addClass(\"F\").store(\"hidden\", false);\n\n this.highlightOption(this.o.selectedIndex);\n\n this.fireEvent(\"onContainerShow\", this.selectedIndex);\n },\n\n clicked: function(ev)\n {\n if(!this.isDisabled())\n {\n if( ev.target != null )\n {\n var oTarget = $(ev.target);\n\n if( oTarget.getParent() == this.container )\n {\n this.selectOption(oTarget.retrieve(\"index\"), true);\n this.hideContainer();\n this.parent();\n this.o.selectedIndex = oTarget.retrieve(\"index\");\n this.o.fireEvent(\"change\");\n return;\n }\n else if(this.options.scrolling && oTarget.getParent(\".\"+this.scrollerWrapper.getProperty(\"class\")) == this.scrollerWrapper)\n {\n //console.log(\"no toggle\");\n return;\n }\n }\n\n this.toggle();\n this.parent();\n }\n },\n\n toggle: function()\n {\n this.containerWrapper.retrieve(\"hidden\") == true ? this.showContainer() : this.hideContainer();\n },\n\t\n keyup: function(ev)\n {\n // toggle on alt+arrow\n if(ev.alt && (ev.key == \"up\" || ev.key == \"down\") )\n {\n this.toggle();\n return;\n }\n\n switch(ev.key){\n case \"enter\":\n case \"space\":\n this.toggle();\n break;\n\n case \"up\":\n this.updateOption(-1);\n break;\n\n case \"down\":\n this.updateOption(1);\n break;\n\n case \"esc\":\n this.hideContainer();\n break;\n \n default:\n this.o.fireEvent(\"change\");\n break;\n }\n },\n\n keydown: function(ev)\n {\n if(ev.key == \"tab\")\n {\n this.hideContainer();\n }\n },\n\n clickedOutsideListener: function(ev)\n {\n if ($(ev.target).getParent(\".\"+cfe.prefix+this.type) != this.a && !( (Browser.ie || Browser.opera) && ev.target == this.o) && ( this.l == null || (this.l && $(ev.target) != this.l) ) ) this.hideContainer();\n },\n\n update: function()\n {\n this.parent();\n this.selectOption(this.o.selectedIndex);\n }\n});", "demo.html": "\n\n \n \n \n\n \n \n \n \n\n \n \n

      CFE Barebone Example

      \n

      for mootools 1.2

      \n

      \n Visit homepage\n

      \n\n
      \n\n\n
      Checkboxes (input[checkbox])\n \n\n
      \n\n
      Checkboxes with implicit labelling\n

      NOTE: 3rd Checkbox has dependencies: 1st and 2nd get automatically checked if not already

      \n
        \n
      • \n
      • \n\n
      • \n
      • \n\n
      • \n\n
      \n
      \n\n\n
      Radiobuttons (input[radio])\n
        \n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n
      • \n\n
      • \n
      • \n\n\n
      • \n
      • \n\n
      • \n
      • \n
      \n
      \n\n\n
      Textinput&-area(input[text,password],textarea)- w/ slidingDoors\n
        \n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • trigger textfield 4 disabled/enabled\n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • trigger textarea 2 disabled/enabled\n
      • \n\n
      • \n \n
      • \n
      \n
      \n\n\n\n
      Textinput&-area with implicit labelling\n
        \n
      • \n
      • \n\n
      • \n
      • \n\n
      • \n
      • \n\n
      • \n\n
      • \n\n
      • \n
      • \n
      \n
      \n\n\n\n \n\n
      Selectfield (select) with and without multiple option and preselected\n
        \n\n
      • \n \n
      • \n\n
      • \n\n \n
      • \n\n
      • \n \n
      • \n\n
      • trigger select 3 disabled/enabled\n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • trigger multiple select 2 disabled/enabled\n
      • \n
      \n
      \n\n\n\n
      file upload (input[file]) -- without and with implicit labelling\n
        \n
      • \n \n
      • \n\n
      • \n
      • \n\n
      • \n \n
      • \n
      \n
      \n\n\n
      \n Check POST Data or Reset Data via Buttons (input[submit], input[reset], input[image])\n\n
        \n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n\n
      • \n \n
      • \n
      \n\n
      \n\n
      Advanced example: Search field\n
        \n
      • \n \n \" name=\"inputSearchSubmit\" />\n
      • \n
      \n
      \n
      \n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n", "cfe/modules/select/cfe.module.select.multiple.js": "/**\n * @module Selectable\n */\n\n/**\n * replaces select fields with attribute multiple set\n *\n * bug:\n * mouseWheel support needed\n * \n * @class SelectMultiple\n * @namespace cfe.module\n *\n * @extends cfe.module.Select\n */\ncfe.module.SelectMultiple = new Class({\n\t\n Extends: cfe.module.Select,\n instance: 0,\n\n /**\n * CSS Selector to fetch \"original\" HTMLElements for replacement with this module\n * @property selector\n * @type string\n */\n selector: \"select[multiple]\",\n\n options: {\n buttonStyle: false\n },\n\n afterInitialize: function()\n {\n this.containerWrapper.addClass(cfe.prefix+\"SelectContainerWrapper\").setStyles({\n \"position\": \"relative\",\n \"z-index\": \"auto\"\n });\n this.container.addClass(cfe.prefix+\"SelectContainer\");\n\n this.o.addEvents({\n onDisable: function(){\n this.containerWrapper.getElements(\"input, button\").each(function(el){\n el.disable();\n });\n }.bind(this),\n onEnable: function(){\n this.containerWrapper.getElements(\"input, button\").each(function(el){\n el.enable();\n });\n }.bind(this)\n });\n \n this.parent();\n },\n\n setupWrapperEvents: function()\n {\n this.a = this.containerWrapper;\n this.parent();\n },\n\n buildOption: function(el, index)\n {\n var oOpt = new cfe.module.Checkbox({\n label: el.innerHTML,\n checked: (el.selected != null),\n disabled: this.isDisabled()\n });\n oOpt.index = index;\n\n oOpt.addEvents({\n \"check\": function(index){\n this.origOptions[index].selected = true;\n this.o.fireEvent(\"change\")\n }.pass(index, this),\n \"uncheck\": function(index){\n this.origOptions[index].selected = false;\n this.o.fireEvent(\"change\")\n }.pass(index, this)\n });\n\n $(oOpt).addClass(cfe.prefix+\"Option \"+cfe.prefix+\"Option\"+index+(el.get('class')?\" \".el.get('class'):\"\")).disableTextSelection();\n oOpt.getLabel().removeEvents().inject( $(oOpt) );\n\n return $(oOpt);\n },\n\n selectOption: function(index)\n {\n index = index.limit(0,this.origOptions.length-1);\n\n this.highlightOption(index);\n },\n\n clicked: function()\n {\n if(!this.isDisabled())\n {\n this.o.focus();\n this.fireEvent(\"onClick\");\n }\n },\n\n update: function()\n {\n this.fireEvent(\"onUpdate\");\n },\n\n toggle: function(){},\n keydown: function(){},\n hideContainer: function(){},\n showContainer: function(){}\n});"}}